Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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>
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 :( –  Shen Xu Sep 19 '12 at 10:35

2 Answers 2

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>
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

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.