I’m trying to create a WordPress plugin that adds a button below all posts. The button is a “Like” button that pass some parameters through the URL to a new site.
The parameters are WordPress permalink, title, and blog name.
Can’t make it work.
function add_bloglovin($content) {
$blog_title = get_bloginfo('name');
$link = the_permalink();
$title = the_title();
$bloglovin ="<br><a href="http://www.bloglovin.com/like/?b=$blog_title&p=$link&t=$title" onclick="window.open(this.href, 'bloglovin_like', 'width=480,height=320, toolbar=0, location=0, menubar=0, scrollbars=0, status=0'); return false;"><img src="http://www.bloglovin.com/widget/bilder/like.gif"></a>";
return $content .$bloglovin;
}
add_filter('the_content', add_bloglovin);
the_permalink() is a display function. Use get_permalink() to return a string that you can use. To make the_title return just the title with no wrapped HTML you need to use the_title(”,”,false);
From the WordPress Codex:
http://codex.wordpress.org/Function_Reference/the_permalink
Function Reference/the permalink
You can’t use $link = the_permalink(); in isolation unless it’s in the Loop.
Try a basic sanity check by
var_dump()
ing the$link
and$title
variables. Do they actually contain a string?