WordPress.org

Ready to get started?Download WordPress

Forums

Facebook Share Can't Work No Matter What (8 posts)

  1. alexkwa
    Member
    Posted 1 year ago #

    Hello all,

    I have no plugins running. But I can't seem to get Facebook to share my excerpt as a description and thumbnail image as the og:image. I've researched and tried everything, please help. Here's my current code:

    <?php
    	$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
    	$thumb = wp_get_attachment_image_src($thumb[0], false);
    	$thumb = $thumb[0];
    	$default_img = get_bloginfo('stylesheet_directory').'/img/logo.png';
    
    	?>
    
    <?php if (is_home()) { ?>
    <meta property="og:description" content="<?php bloginfo('description'); ?>" />
    	<meta property="og:image" content="<?php bloginfo( 'template_url' ); ?>/img/logo_l.png" />
    <title><?php echo get_bloginfo ( 'name' );  ?> - <?php echo get_bloginfo ( 'description' );  ?></title>
    <meta property="og:type" content="blog" />
    
    <?php } 
    
    if (is_singular() || is_single() || is_page()) { ?>
    <title><?php single_post_title(''); ?></title>
    <meta property="og:type" content="article" />
    	<meta property="og:title" content="<?php single_post_title(''); ?>" />
    
    	<meta property="og:description" content="<?php
    	while(have_posts()):the_post();
    	$out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", get_the_excerpt());
    	echo apply_filters('the_excerpt_rss', $out_excerpt);
    	endwhile; 	?>" />
    
    	<meta property="og:url" content="<?php the_permalink(); ?>"/>
    	<meta property="og:image" content="<?php if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
    
     <?php }; ?>
  2. CrusaderX3
    Member
    Posted 1 year ago #

    Hi alexkwa,

    Try these two tutorials :

    1.Post Excerpt in Facebook Link Description
    Click Here

    2. Tutorial: Show Featured Image In Facebook Click Here

  3. alexkwa
    Member
    Posted 1 year ago #

    Hello,

    First of all, thank you so much for your reply. I've actually tried these tutorials out before.
    The first tutorial does not work for me. This is the code for single pages.

    <?php if (is_singular() || is_single() || is_page()) { ?>
    <title>
    <?php single_post_title(''); ?>
    </title>
    <?php
    global $post;
    setup_postdata($post);
    ?>
    <meta name=”description” content=”<?php the_excerpt_rss(); ?>” />
    <meta property="og:type" content="article" />
    <meta property="og:title" content="<?php single_post_title(''); ?>" />
    <meta property="og:url" content="<?php the_permalink(); ?>"/>
    <meta property="og:image" content="<?php if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
    <?php }; ?>

    For Tutorial 2, the given code

    <span>function insert_image_src_rel_in_head() {
    	global $post;
    	if ( !is_singular()) //if it is not a post or a page
    		return;
    	if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
    		$default_image="<a class="linkclass" href="http://example.com/image.jpg">http://example.com/image.jpg</a>"; //replace this with a default image on your server or an image in your media library
    		echo '';
    	}
    	else{
    		$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
    		echo '';
    	}
    	echo "n";
    }
    add_action( 'wp_head', 'insert_image_src_rel_in_head', 5 );
    
    </span>

    causes a parse error (Parse error: syntax error, unexpected '<' in /home/alexkwa/alexkwa.com/wp-content/themes/alexkwa/functions.php on line 4)

    Appreciate any help I can get. alexkwa.com is my site btw.

  4. alexkwa
    Member
    Posted 1 year ago #

    I really could appreciate any help on this. I've tried a long while by myself...

  5. elvenstar
    Member
    Posted 1 year ago #

    alexkwa, you're not alone - I have this problem too, and it's only begun after I upgraded to WordPress 3.4.2
    (My secondary blog is still running on version 3.4 and sharing links to that blog work perfectly. The plugins on both my blogs are pretty much the same too, so I'm forced to conclude that it has to do with the upgrade...)

    Nothing I've tried seems to work, and my own request for help on the forum here hasn't received any response as yet either - guess there's no real solution for it, maybe? :/

  6. Alex Kwa
    Member
    Posted 1 year ago #

    That's just bull. :( I managed to get the descript working, but not the thumbnail, even tho the source pulls the right image, the right image doesnt show when shared...

  7. paintedcliffs
    Member
    Posted 1 year ago #

    I don't know if this will help, but I got my chosen thumbnail to show up when I shared my site in Facebook by adding this to the header.php (in my TwentyEleven child theme), right under </title>:

    '<meta property="og:image" content="YOUR IMAGE URL HERE" />'

    I had added the thumbnail image to my media library and copied the full URL from there. It worked perfectly.

    However, I'm having trouble getting the proper title of the web site to show up when I post to Facebook. It annoying reads "Home" which is the name of the static homepage I created. AlexKwa, how did you get the description to work?

    My site is

  8. paintedcliffs
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic