I use a theme to build an portfolio.
I´d like to add an pinterest “pin-it button” into the fuctions.php:
Facebook, Google+ an Twitter were done, just the pinterest won´t work.
Can´t found the the wrong code.
This ist my code:
function share_this($content){
if ( is_singular( 'portfolio' ) ) {
$content .= '<div class="share-this">' .
/* Facebook */
'<div class="facebook-like-button">' .
'<iframe src="http://www.facebook.com/plugins/like.php?href='. urlencode( get_permalink( $post->ID ) ) .
'&layout=button_count&show_faces=false&width=200&action=like&colorscheme=light&height=21"' .
'scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe>' .
'</div>' .
/* Pinterest */
'<div class="pinterest-it-button">'
'<a href="http://pinterest.com/pin/create/button/?url=<?php echo get_permalink(); ?>&media=<?php echo get_thumbnail(); ?>
'&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a>
'<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>'.
'</div>' .
/* Googgle+ */
'<div class="plusone"><g:plusone size="medium" href="'.get_permalink().'"></g:plusone></div>' .
/* Twitter */
'<div><a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a></div>' .
'</div>';
}
Thanks
There were several errors in your code. The biggest was that the function didn’t even have a closing bracket, but we can probably assume that was just not copied into your post, otherwise nothing would have been working for you.
This is a filter on the content right?
It looks like you want to append these shares after your post content.
If that’s the case than you would need this line as well:
Other than that, you were trying to close php tags and open them in your statement where you are appending string data to the
$content
variable. You were also trying to echo data and used functions to echo instead of return (for examplethe_title
echos instead ofget_the_title
which returns the value).Instead of one big string appended to your content, I cleaned things up using an array-building method, but multiple
$shares .=
would have worked too.This should work although I have not tested it.
You are building the URL Wrong since first it needs to be urlencoded and 2nd what is
get_thumbnail()
does it print the full img tag? and 3rd you are echoing it out.anyway try this
Your issue is simple php syntax. You can’t use opening and closing php braces
<?php
and?>
within variable assignment and separate strings and variables must be concatenated by a dot.
Follow the G+ and Facebook buttons as examples. I also assume you want to
return
your results?