0
votes

In the Facebook "like button" the and code snippets both require that an individual page URL be specified. The like button code snippet should go into an include, so obviously I would like to use some kind of variable in the like button code snippet so that it can automatically detect the current page URL. The Twitter, LinkedIn and GooglePlus buttons all automatically detect.

Here's my code. It's working just fine, but you can see where the individual page URL is being specified. Is there a variable that can be used instead, so the code snippet can be placed into an include?

Thanks.

<iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.[MYWEBSITE].com%2F[MYPAGENAME.shtml]&send=false&layout=standard&width=50&show_faces=false&action=like&colorscheme=light&font=tahoma&height=20" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:46px; height:20px;" allowTransparency="true"></iframe>

2

2 Answers

1
votes

You can achieve this by using XFBML/HTML5 version of Like Button and omitting href/data-href attribute, by not including it in the code you're instructing JS-SDK to use current page URL while rendering Like Button.

0
votes

You can do this with iframe.

My code is:

<iframe src="//www.facebook.com/plugins/like.php?href='. get_permalink( get_the_ID() ) .'&amp;width&amp;layout=button_count&amp;action=like&amp;show_faces=false&amp;share=false&amp;height=21&amp;appId=438288506277662" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>

Notice the important part:

href='. get_permalink( get_the_ID() ) .'

Hope that helps! - Jack