WordPress.org

Forums

Facebook not picking up post or blog description when sharing (4 posts)

  1. aderojas
    Member
    Posted 3 years ago #

    Hello there,

    I can't get Facebook to use the blog description or each post description when sharing, either through social plugins (Jetpack's Sharedaddy and Digg Digg) or just by copy/pasting the URL in the Facebook status.

    Right now when sharing on FB it shows the post title where it should show the description, while the image and title are fine. I went through it and found this line in the posts code.

    "<meta property="og:description" content="[whatever the post title is]">

    It's generated by Jetpack's Sharedaddy plugging, so I removed the Facebook button from the plugin options and the og:description dissapeared from the code.... but still when sharing the post to Facebook the description was just the title, sharing it either through the buttons from Digg Digg plugin or by copy-pasting
    the URL.

    So I kept searching and I found the generator of the line at plugins/jetpack/modules/sharedaddy/sharing-sources.php:

    public function display_header() {
    		if ( $this->share_type == 'share' ) {
    			// Set the open graph description, otherwise Facebook may pick up some random text from the page
    			global $post;
    
    			if ( $post && $post->ID > 0 )
    				echo '<meta property="og:description" content="'.esc_attr( apply_filters( 'sharing_post_title', $post->post_title, $post->ID, $this->id ) ).'>" />';
    		}

    I edited, and whatever I write is what it shows (meaning: if I make a php call to something it shows the php, not what it should be calling). I tried with these two:

    echo '<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt()); ?>" />';
    
    echo '<meta property="og:description" content="test" />';

    And I got these in the source code of the posts:

    "<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt()); ?>">
    
    "<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt()); ?>">

    But in both cases, when sharing to Facebook the description shown was just the title of the post.

    Any idea what is doing this and how can I remove it? I'm using All in One SEO plugin and I would like it Facebook to pick the description from there and, when there isn't, just take the first paragraph or so.

    The blog is at http://www.enquepiensauncalcetin.com. I'm using WordPress 3.3.1, and the theme is a free one I edited so I have full access to it.

    Thanks!

  2. pstjean
    Member
    Posted 3 years ago #

    First of all, you can't echo PHP code and then expect PHP to parse it again after it's been echoed :) Also, it's not a good idea to edit plugins. The next time the plugin updates, it will overwrite your changes, and you'll be back to square one.

    I usually just hard-code these meta tags into the header, rather than using a plug-in. The code you posted should work just fine if you put it in the header of your theme, rather than trying to echo it out.

  3. aderojas
    Member
    Posted 3 years ago #

    Thanks ;) No idea what "echo PHP code means", though!

    The problem is that if I add those tags by hand into the header, then when I use the plugings to share on facebook (I can't just code that) I feel they are going to either overwrite them or duplicate the tags. Also, when I write an specific description in the SEO plugin I want Facebook to pick that, instead of the default description. It works with Google.

    I understand what All in One SEO ads is my fault, but the default Jetpack Sharing plugin should have this solved!

  4. technologypoet
    Member
    Posted 2 years ago #

    Dresde, you pointed me in the right direction, after a few hours of hacking this morning I finally got it to work. The explanation is a bit long, check out: How to fix Jetpack's broken og:description.

    Hopefully this helps!

Topic Closed

This topic has been closed to new replies.

About this Topic