Title: Proper PHP syntax for Facebook like button?
Last modified: August 19, 2016

---

# Proper PHP syntax for Facebook like button?

 *  [Rich Owings](https://wordpress.org/support/users/gpsmapper/)
 * (@gpsmapper)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/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 [http://developers.facebook.com/docs/reference/plugins/like](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](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](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737220)
 * check out this [WP-Snippet](http://wp-snippets.com/share-on-facebook/).
 *  Thread Starter [Rich Owings](https://wordpress.org/support/users/gpsmapper/)
 * (@gpsmapper)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737233)
 * 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.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737414)
 * 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](http://wordpress.org/extend/plugins/search.php?q=facebook+like)
 *  Thread Starter [Rich Owings](https://wordpress.org/support/users/gpsmapper/)
 * (@gpsmapper)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737447)
 * 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.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737448)
 * 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](https://wordpress.org/support/users/gpsmapper/)
 * (@gpsmapper)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737449)
 * In a sidebar text widget. It’s not currently active, but it would be in the right
   sidebar on [http://gpstracklog.com](http://gpstracklog.com), just below the FB
   icon and FB text link. There is an active version at [http://test.gpstracklog.com](http://test.gpstracklog.com)
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737450)
 * 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](https://wordpress.org/support/users/gpsmapper/)
 * (@gpsmapper)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737451)
 * In the widget’s text field.
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737460)
 * 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](https://wordpress.org/support/users/gpsmapper/)
 * (@gpsmapper)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737463)
 * 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.
 *  [Xephan](https://wordpress.org/support/users/xephan/)
 * (@xephan)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737470)
 * 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.

## Tags

 * [permalink](https://wordpress.org/support/topic-tag/permalink/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 11 replies
 * 4 participants
 * Last reply from: [Xephan](https://wordpress.org/support/users/xephan/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/proper-php-syntax-for-facebook-like-button/#post-1737470)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
