1. Home
  2. Knowledge Base
  3. Developer
  4. WordPress
  5. Render MightyShare Image PHP Function

Render MightyShare Image PHP Function

Developers can use the Mightyshare_Public_Functions::get_mightyshare_url($post->ID) function to get the MightyShare image URL for a specific post. This is great for using MightyShare images in custom templates, themes or other areas of your site.

Using the Function

Here’s an example of how to use the function, including overwriting aspects of the template.

Mightyshare_Public_Functions::get_mightyshare_url($post->ID, ['width' => 2000, 'height' => 800]);

Of course you can simply use the function without any overwriting, and it will use the default template settings.

Mightyshare_Public_Functions::get_mightyshare_url($post->ID);

Add MightyShare Image to RSS Feed

Here’s how to add the MightyShare image to your RSS feed:

add_filter('the_content', 'prepend_mightyshare_to_rss');

function prepend_mightyshare_to_rss($content) {
    global $post;
    $mightyshare_url = Mightyshare_Public_Functions::get_mightyshare_url($post->ID);
    $prepend_content = '<img src="'. esc_url($mightyshare_url) .'" alt="Social Share Image">';
    
    if(is_feed()) {
        $content = $prepend_content . $content;
    }
    return $content;
}

Incorporating MightyShare images into your WordPress site, whether through custom templates or by enhancing your RSS feed, can significantly boost your content’s. The Mightyshare_Public_Functions::get_mightyshare_url function provides a straightforward way to achieve this.

Was this article helpful?

Related Articles