-1

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</a>
  • 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
1

You can try using this:

<?php
$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>
0

Try..

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

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

note

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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