• I am trying to add code to my functions.php to allow addthis to show up on specific pages. According to the documentation, the filters in the 6.0 version have changed.

    My quick and dirty filter example to disable on all pages does not seem to work:

    add_filter('addthis_sharing_buttons_enable', 'my_addthis_sharing_buttons_enable');
    function my_addthis_sharing_buttons_enable($enable) {
      return false;
    }

    When I enable this, the addThis buttons still appear on every page. Shouldn’t this example hide the share buttons on every single page, or am I misunderstanding the filter?

    Thanks for your help!

    • This topic was modified 1 year, 8 months ago by  insidethepark.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Julka Grodel

    (@jgrodel)

    Hi insidethepark.

    Thanks for reaching out to us with your issue.

    I believe your assumption here is correct and I will take a deeper looking into it. In the meantime, do you have a URL you could share with us that has buttons showing up where you don’t expect them to? It would help with the troubleshooting.

    One other thing to consider is caching. If you’re using any caching plugins, you might want to clear their caches after adding in this code in order to see the changes on the page.

    Thanks,
    Julka

    Hi Julka,

    The development is happening on my local machine, so I don’t have a publicly available URL yet.

    I can confirm there is no caching occuring on the local site.

    Thanks!

    Plugin Contributor Julka Grodel

    (@jgrodel)

    Hi insidethepark.

    I tried your code in the functions.php file of the active theme (twentyseventeen) in a clean WordPress install. It worked as expected, with buttons above and below posts (both on the pages for the posts and excerpts for the posts) disappearing.

    Have you done some troubleshooting to make sure your code is executing, like an error_log or echo right above where you’re defining your filter?

    Thanks,
    Julka

    • This reply was modified 1 year, 8 months ago by  Julka Grodel.

    Hi Julka,

    I can confirm the filter works when the display is set to top/bottom of the page. However, I am using the Sidebar display, and the filters do not seem to work on that. Is there a filter for the sidebar?

    Thanks!

    Plugin Contributor Julka Grodel

    (@jgrodel)

    Hi insidethepark.

    No, unfortunately, there are no filters for that.

    Depending on your mode, you’ll see one of two things when editing the sharing sidebar. There will either be an Advanced Settings section in the Sidebar configurations where you can define URL patterns on which to hide that tool, or a Templates section with options like homepage, pages, post, categories.

    Thanks,
    Julka

    @jgrodel, Is there a filter we can use to programmatically alter the display options under Templates section (homepage, pages, post, categories), instead of having those to be dictated from the backend UI configuration page only?

    For instance, I would like to display the Sidebar Floating Shares on certain post detail pages, not all of them, and I’d like to dynamically control this from functions.php using ideally a WP filter.

    Looking at the filters docs I’m not quite sure which should I follow for that.

    NVM, I resolved this using addthis_layers_array filter to conditionally output the share floating sidebar anywhere I need it.

    e.g.

    add_filter( 'addthis_layers_array', function ( $addthis_layers ) use ( $post ) {
    
    	if ( $post->my_custom_field == 'my_value' ) {
    
    		$addthis_layers = array(
    			'share' => array(
    				'position'  => 'left',
    				'services'  => 'twitter,facebook,linkedin,email'
    				)
    			);
    
    	}
    
    	return $addthis_layers;
    });

    More info at this gist: https://gist.github.com/elvismdev/d776e443c396360b45fb617589ac9395

    • This reply was modified 1 year, 8 months ago by  Elvis Morales.
    • This reply was modified 1 year, 8 months ago by  Elvis Morales.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Filtering Issue’ is closed to new replies.