Using php in Genesis Simple Hook to hook social sharing buttons prevent Twitter from getting post’s title

issue:

using php in Genesis Simple Hook modify the code hoocked. is it a known bug or am I doing something wrong?

what I did

I wrote a custom code for social sharing buttons and put it in the genesis_entry_footer with the plugin genesis simple hook. Unfortunately, this way the social sharing buttons are shown even in the archive page and blog page. To avoid this I used a php if statement (if (is_singular(post)). But, this way the twitter code don’t get the title of the article, while If I don’t use php I get the article’s title passed to twitter composing window.

the code I used

<?php 
if (is_singular(post)) {
echo '
<div style="text-align:center">
<!-- Twitter -->
<a href="https://twitter.com/intent/tweet?source=http%3A%2F%2F37.60.224.253%2F~silviogu%2Fstaging.com%2F&text=:%20http%3A%2F%2F37.60.224.253%2F~silviogu%2Fstaging.com%2F&via=silviogulizia" target="_blank" title="Tweet" onclick="window.open("https://twitter.com/intent/tweet?text=" + encodeURIComponent(document.title) + "%20-%20"  + encodeURIComponent(document.URL)); return false;" class="share-btn twitter">
    <i class="fa fa-twitter"></i>
</a>

<!-- Facebook -->
<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2F37.60.224.253%2F~silviogu%2Fstaging.com%2F&t=" title="Share on Facebook" target="_blank" onclick="window.open("https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(document.URL) + "&t=" + encodeURIComponent(document.URL)); return false;" class="share-btn facebook">
    <i class="fa fa-facebook"></i>
</a>

<!-- LinkedIn -->
<a href="http://www.linkedin.com/shareArticle?mini=true&url=http%3A%2F%2F37.60.224.253%2F~silviogu%2Fstaging.com%2F&title=&summary=&source=http%3A%2F%2F37.60.224.253%2F~silviogu%2Fstaging.com%2F" target="_blank" title="Share on LinkedIn" onclick="window.open("http://www.linkedin.com/shareArticle?mini=true&url=" + encodeURIComponent(document.URL) + "&title=" +  encodeURIComponent(document.title)); return false;" class="share-btn linkedin">
    <i class="fa fa-linkedin"></i>
</a>

<!-- Email -->
<a href="mailto:?subject=&body=:%20http%3A%2F%2F37.60.224.253%2F~silviogu%2Fstaging.com%2F" target="_blank" title="Send email" onclick="window.open("mailto:?subject=" + encodeURIComponent(document.title) + "&body=" +  encodeURIComponent(document.URL)); return false;" class="share-btn email">
    <i class="fa fa-envelope"></i>
</a>
</div>';
}
?>

Read more here: Using php in Genesis Simple Hook to hook social sharing buttons prevent Twitter from getting post’s title

Leave a Reply

Your email address will not be published. Required fields are marked *