WordPress.org

Ready to get started?Download WordPress

Forums

Jetpack by WordPress.com
[resolved] Custom og:image for homepage not working (4 posts)

  1. Mercifull
    Member
    Posted 1 year ago #

    Hi,

    Often when people link to my website on Facebook (www.frome.fm) it often automatically adds one of the images of our sponsors instead of chosing something more appropriate.

    I have used the code found at http://jetpack.me/2013/07/12/add-a-default-image-open-graph-tag-on-home-page to make a functionality plugin however this does not seem to have worked.

    Viewing the source html still shows the following:
    <meta property="og:image" content="http://wordpress.com/i/blank.jpg" />

    Instead of the image url I would prefer:
    http://frome.fm/wp-content/uploads/2013/02/Vote-FFM-slider.jpg

    Any idea?

    Thanks.

    https://wordpress.org/plugins/jetpack/

  2. Mercifull
    Member
    Posted 1 year ago #

    I added in the code for the custom Twitter tag which did work but the custom image did not.

  3. Mercifull
    Member
    Posted 1 year ago #

    <?php
    /*
    Plugin Name: Matts OG:image fallback
    Plugin URI: http://www.frome.fm
    Description: Functionality plugin to add default open graph image to homepage when no featured image found. Also adds @FromeFM to a Twitter meta tag. Requires Jetpack. Code from http://jetpack.me/tag/open-graph/
    Version: 0.4
    Author: Matt Sims, Automattic
    Author URI: http://www.mattsims.com http://www.jetpack.me
    */
    
    function fb_home_image( $tags ) {
        if ( is_home() ) {
            // Remove the default blank image added by Jetpack
            unset( $tags['og:image'] );
    
            $fb_home_img = 'http://frome.fm/wp-content/uploads/2013/02/Vote-FFM-slider.jpg';
            $tags['og:image'] = esc_url( $fb_home_img );
        }
        return $tags;
    add_filter( 'jetpack_open_graph_tags', 'fb_home_image' );
    }
    
    function tweakjp_custom_twitter_site( $og_tags ) {
    	$og_tags['twitter:site'] = '@FromeFM';
    	return $og_tags;
    }
    add_filter( 'jetpack_open_graph_tags', 'tweakjp_custom_twitter_site', 11 );
    ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

  4. Mercifull
    Member
    Posted 1 year ago #

    Resolved. Was a simple case of a misplaced }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic