Dealing With sharer.php

In many themes and plugins the integration with facebook does not do the important work of stripping tags and non text characters from the share url. Many plugins needs to put styling and javascript in the posts to make the maps work, and to provide the custom look and feel, so commonly these no text items will show up when Facebook calls back and tries to get the content associated with the post. In is our opinion that this is a mistake on the parts of both the theme/social plugin developers, and with facebook for not stripping no text items. As a work around we propose the following modification to any theme or plugin using share.php. The example has line breaks so it can be displayed, the href section should not have any line breaks when used on your site.

The approach relies on identifying the “Featured Image”, which wordpress interprets by the ‘single-post-thumbnail’. See Featured Images Support for more info.

<li class="shareFacebook">
    <a rel="nofollow" 
    href="http://www.facebook.com/share.php?
      s=100
      &p[title]=<?php the_title();?>
      &p[url]=<?php the_permalink(); ?>
      <?php if (has_post_thumbnail( get_the_ID() )) : ?>
        <?php $image = 
           wp_get_attachment_image_src( 
             get_post_thumbnail_id( get_the_ID() ), 
             'single-post-thumbnail' ); ?>
        &p[images][0]=<?php echo $image[0]; ?>
      <?php endif; ?>
      &p[summary]=
       <?php echo 
         urlencode(substr(strip_tags(the_excerpt()), 0, 250)); 
       ?>" 
     title="Share this post on Facebook" 
     target="_blank">Facebook</a>
    </li>

Sadly these aspects of sharer.php are very poorly documented by facebook, the best documentation we have found on this is at daddydesign.com. Hope this helps.

About clay

Clay is the founder of welocally. Making location aware applications that help people become independent is a passion for Clay. Want to know more about him? Just ask.
No comments yet.

Leave a Reply


six + = 10