0

I want to put the option to share (with share buttons in post footer) but just in some specifics posts, and I want to control this in the admin panel.

I know a plugin, but I want do this "without plugin".

How can I do this?

0

Use conditional tags

You can hook in a div for AddThis using conditional tags and WordPress or theme specific hooks from your functions file.

Hook Buttons in Using Custom Function

In this example, wp_footer

function wpsites_function() {
if ( is_single(array( 1, 2, 3, 4, 5 ) ) ) {
    echo '<div class="addthis_native_toolbox"></div>';
}}
add_action('wp_footer', 'wpsites_function');

Change wp_footer to any other WordPress hook position or theme specific hook.

Add Code In Template

You could also add the code with conditional tag directly to your child themes single.php file in the position you want the buttons to display.

Load Javascript for Buttons

You'll need to load the js for the AddThis script on every page you want the buttons after you create you own account and use your own publisher i,d in the code.

<!-- Go to www.addthis.com/dashboard to customize your tools -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52f6368a531ddc3b"></script>

You can do this using wp_enqueue_scripts

Or use the Header and Footer scripts box your theme includes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.