Support » Plugins » Hacks » Proper PHP syntax for Facebook like button?

  • Hi,

    I’m wanting a Facebook like button on my home page (I have it working fine on individual posts) and I’m getting different results depending upon the way I implement it.

    If I generate code from and plug in my URL, I get a button saying 17 people have liked the page.

    But if I use PHP code instead of the URL , like this…

    <iframe src="<?php the_permalink(); ?>&layout=button_count&show_faces=false&width=100&action=like&colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:20px;"></iframe>

    …I get a button saying 240 people have liked it. Much better!

    But if someone clicks to Like it, their FB profile shows…

    NAME likes http://</?php+the_permalink%28%29%3B+%3F%3E

    Any suggestions for variations of php the_permalink that I can try?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator t-p


    check out this WP-Snippet.

    Thread Starter Rich Owings


    Thanks. I changed it to <iframe src="<?php the_permalink(); ?>&t=<?php the_title(); ?>&layout=button_count&show_faces=false&width=100&action=like&colorscheme=dark" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:100px; height:20px;"> but it still generates gobbledy-gook on their FB page when someone likes it.

    Why did you change it? Did you try the code that was suggested?

    Maybe a plugin solution would be better suited?

    Thread Starter Rich Owings



    Thanks for taking the time to reply.

    I tried the code generated from the Facebook developer site. I changed it because it was generating a low number of likes compared to code using ?php the_permalink(); ?.

    I didn’t try the WP-Snippet because I’m wanting the like button and a current count to show.

    I tried one highly rated plugin (don’t recall which) for individual posts, but when I told it to place a Like button at the top and bottom of the posts, it put them following the <!–more–> break.

    I ended up manually coding the FB Like and Twitter buttons into my post and page template files and they work great, but I really want a LIKE button for the home page too.

    Where are you placing this code, into a field in a theme option, or one of the theme’s template files?

    No idea how these like buttons work myself(don’t use facebook, etc), but it’s still just code, it should be a relatively simple process..

    Thread Starter Rich Owings


    In a sidebar text widget. It’s not currently active, but it would be in the right sidebar on, just below the FB icon and FB text link. There is an active version at

    Ok, but are you entering the code into the widget’s text field or into the sidebar file in the current theme’s folder?

    Thread Starter Rich Owings


    In the widget’s text field.

    The code is out of context inside the text field of a widget though, and additionally they do not except PHP code (though plugins can enable this).

    Ideally this code belongs in the sidebar file. If you want the code only included on particular pages you can work around that by creating an additional sidebar file and including that sidebar (in place of the regular one which should be the same minus the like code) under your chosen conditions..

    If you would like me to explain or clarify anything said above let me know… 😉

    Thread Starter Rich Owings


    Doh! I should have figured that out. I think I’m going to give up, since there is a Facebook issue I haven’t been able to figure out (why its reporting different numbers of followers). I think I’ll just go with their stock code; the “Like” count will build with time.

    Thanks for your help.

    It’s probably different because your PHP code was sending the wrong URL via the text widget rather than your actual URL.

    Facebook appears to match URL up to a certain point, I’ve tried chopping off characters from an URL and it still shows the correct count.

    So the chances are somebody else was trying to do the same thing and therefore generated the extra likes you see for the incorrect gobbleygook.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Proper PHP syntax for Facebook like button?’ is closed to new replies.