Conditionally display Genesis Social Share, e.g. not on a specific category


If you find this free website useful – why don’t you support this with a donation? It is easy…. read more ….

The Genesis Social Share plugin is one of the must have plugins for Genesis sites. See https://wordpress.org/plugins/genesis-simple-share/

I wanted to display these icons (just like the ones on this post) except on posts in a specific category.  I had to read the plugin code to work this out. Fortunately the code is an example of beautifully written code. However my first attempts didn’t work, there was some trial and error required finding the right hooks and I’m still not 100% certain why this works and my other attempts didn’t.

So add this code to your functions.php (suitably modified for your specific conditions) and I hope it will work for you.

add_action( 'genesis_before', 'myfunc_genesis_before' );

function myfunc_genesis_before() {
    // check to see if a single post and in a category (changes as required )
    if ( is_single && in_category('my-category')) {
        global $Genesis_Simple_Share;
	remove_action( 'genesis_loop', array( $Genesis_Simple_Share, 'start_icon_actions' ), 5  );
	remove_action( 'genesis_loop', array( $Genesis_Simple_Share, 'end_icon_actions'   ), 15 ); 
		}

}

 

 

, ,

Leave a Reply

Your email address will not be published.