I am trying to write a plug-in to display the RunKeeper Healthy button on single posts, but my output has an extra space and double-quote when I look at the page source. What I'm trying to do with the button is open a new window via inline JavaScript.
I've tried switching between single and double quotes and have also ensured that I was escaping nested quotes properly. Trying to append the get_permalink() breaks the generated link for the RunKeeper sharing URL. The image tag for the link itself is fine, but I see an incomplete link when I hover over it.
The link output is:
<a href="javascript:void(window.open('http://runkeeper.com/share?healthyUrl=http://my_website/my_post_permalink/ " , '' , 'width=630,height=350');">
But what I would expect is:
<a href="javascript:void(window.open('http://runkeeper.com/share?healthyUrl=http://my_website/my_post_permalink/' , '' , 'width=630,height=350');">
This is what my plug-in code is so far:
add_filter('the_content', 'add_runkeeper_btn' );
function add_runkeeper_btn($content) {
$output = "";
if (is_single()) {
$output .= "<a href=\"javascript:void(window.open('http://runkeeper.com/share?healthyUrl=";
$output .= get_permalink();
$output .= "', '' , 'width=630,height=350');\">";
$output .= "<img src=\"http://runkeeper.com/static/kronos/images/HealthyButton.png\" class=\"healthyImage\" alt=\"RunKeeper Healthy Button\" />";
$output .= "</a>";
}
return $output . $content;
}
For reference this is what is in the page source of the RunKeeper blog post. I am trying to modify it so that the healthyUrl query parameter references the permalink for the post.
<a href="javascript:var%20d=document,l=d.location;void(window.open('http://runkeeper.com/share?healthyUrl='%20+%20l.href,'','width=630,height=350'));">
<img src="http://runkeeper.com/static/kronos/images/HealthyButton.png" class="healthyImage" alt="RunKeeper Healthy Button">
</a>
