WordPress.org

Ready to get started?Download WordPress

Forums

Proper PHP syntax for Facebook like button? (12 posts)

  1. Rich Owings
    Member
    Posted 3 years ago #

    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 http://developers.facebook.com/docs/reference/plugins/like 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="http://www.facebook.com/plugins/like.php?href=<?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?

  2. Tara
    Member
    Posted 3 years ago #

    check out this WP-Snippet.

  3. Rich Owings
    Member
    Posted 3 years ago #

    Thanks. I changed it to <iframe src="http://www.facebook.com/plugins/like.php?href=<?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.

  4. Mark / t31os
    Moderator
    Posted 3 years ago #

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

    Maybe a plugin solution would be better suited?
    http://wordpress.org/extend/plugins/search.php?q=facebook+like

  5. Rich Owings
    Member
    Posted 3 years ago #

    Mark,

    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.

  6. Mark / t31os
    Moderator
    Posted 3 years ago #

    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..

  7. Rich Owings
    Member
    Posted 3 years ago #

    In a sidebar text widget. It's not currently active, but it would be in the right sidebar on http://gpstracklog.com, just below the FB icon and FB text link. There is an active version at http://test.gpstracklog.com

  8. Mark / t31os
    Moderator
    Posted 3 years ago #

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

  9. Rich Owings
    Member
    Posted 3 years ago #

    In the widget's text field.

  10. Mark / t31os
    Moderator
    Posted 3 years ago #

    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... ;)

  11. Rich Owings
    Member
    Posted 3 years ago #

    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.

  12. Xephan
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic