Social Share (AddThis) buttons required at end of all posts
-
Hello.
I currently use a plugin to display social sharing buttons at the end of each post, but I’d much rather use the built-in feature of Graphene.
This is fine if I want the buttons at the top of the post, but if I want the buttons at the bottom they will only appear on single-page posts. At first I thought it was a bug, but after looking at the code I see this is done on purpose.
I tried moving the appropriate code out of the “if” statement, and while it worked in getting the buttons on every post, it placed the button after other post-footer plugins.
How do I get the social share buttons to appear at the end of every post, immediately after the text/content?
Any help would be much appreciated.
I need this for my http://www.wowcast.de Website as well. Hope some1 knows the answer for it!
sincerly
AdminCreate a functions.php file (if you don’t already have one) in your child theme, and add this code:
<?php
function graphene_custom_addthis_placement(){
graphene_addthis( get_the_ID() );
}
add_action( 'graphene_after_post_content', 'graphene_custom_addthis_placement' );
?>Thanks for the code Syahir.
It does work, however I then noticed that you’ll get two instances of the social sharing buttons on a single-post page. LOL.
I haven’t tried it, but I would assume this is easily worked around by doing something like this:
<?php
function graphene_custom_addthis_placement(){
if ( is_single_post() ) :
else :
graphene_addthis( get_the_ID() );
endif;
}
add_action( 'graphene_after_post_content', 'graphene_custom_addthis_placement' );
?>However, I still couldn’t get the buttons above my other end-of-post plugin. In the end, I did it all manually in my child’s functions.php. Fortunately my other end-of-post plugin has an option to use code, and then because I disagree with AddThis forcing a “via @addthis” string to the Tweet button, I did the buttons myself, too.
For those that may want to do something like that, here’s the code I ended up doing (I’m a beginner, so apologies to you demon-coders who could do this with half the lines 🙂
function my_buttons(){
if (is_page()) :
else : ?>
<br>
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
<a href="http://twitter.com/share" class="twitter-share-button"
data-url="<?php the_permalink(); ?>"
data-via="your_twitter_handle"
data-text="<?php the_title(); ?>"
data-count="horizontal">Tweet</a>
<g:plusone href="<?php the_permalink(); ?>" size="medium"></g:plusone>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script><br><h3>You may also like...</h3>
<?php get_related_posts_thumbnails();
endif;
}
add_action( 'graphene_after_post_content', 'my_buttons' );So here I’ve got a Tweet button for the specific post, and G+1 button that does the same. Then after the two buttons I put in a line break before calling the other plugin (a related posts plugin).
Doing it this way allows me to control the order of the plugins, and also do little things like adding an empty line between the end of the post and the sharing buttons.
You can see how it looks here.
Hope this has been helpful to someone 🙂
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.