WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a social sharing widget. It has Facebook sharing option too. I wrote the following link structure for it but when clicked, the page neither displays the link to share, nor the title and decription. Please help out. Thanks

<a href="http://www.facebook.com/sharer.php?u=<?php get_permalink();?>&t=<?phpthe_title();?>">
share|improve this question
Does rest of widget appear? Does anything appear in page source? You are missing space before function call in <?phpthe_title();?> – Rarst Sep 19 '12 at 10:24
@Rarst "social widget" = "sidget". Mhm. Learning new things every day. :) – kaiser Sep 19 '12 at 10:27
@Rarst: Thanks for pointing tht out. I fixed that out. The problem is still there :( – Fahad Uddin Sep 19 '12 at 10:35

You can try using this:

$title = get_the_title( $post_id );
$url = urlencode( get_permalink( $post_id ) );

<a class="fb" target="_blank" href="http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title; ?>&p[url]=<?php echo $url; ?>">Share</a>
share|improve this answer


<a href="http://www.facebook.com/sharer.php?u=
<?php echo get_permalink( $post->ID );?>&t=
<?php echo get_the_title( $post->ID );?>">

I've broken the link up onto separate lines for legibility so you can see what's going on..

Use, <?php echo get_permalink(); ?> and <?php echo get_the_title(); ?> and as Rarst mentioned be mindful of your syntax making sure to put a space between <?php [and your function call]...etc


If your widget is outside of the post loop then you will need to pass the Post ID (on single pages, use get_the_ID()) to both get_the_title and get_permalnik.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.