0

I am using myeffecto plugin for post reaction.The plugin shows emoticons using the_content hook.But i don't want to show it on every posts.i want it in a conditional if() statement

the plugin uses:

add_filter( 'the_content', 'echoEndUserPlugin' );

but i want to use in single.php like this:

if($showreactions){
   // show reactions
}

How can i do it?

1 Answer 1

1

So, the plugin isn't wrapping it in any class which is nice and easy for us. We can't modify the function directly and it doesn't appear to have any filters so what we can do one of 2 things ( which is essentially the same ).

1) If on most pages you don't want this functionality to happen, and consider it a rare case to show emoticons you can remove the hook entirely and only add back in the hook whenever the conditional triggers:

/**
 * Disable My Effecto Plugin emoticons
 * Enable when conditions are met
 *
 * @return void
 */
function theme_myeffecto_disable() {

    remove_filter( 'the_content', 'echoEndUserPlugin' );

    // $showreactions set somewhere?

    if( $showreactions ) {
        add_filter( 'the_content', 'echoEndUserPlugin' );
    }

}
add_action( 'init', 'theme_myeffecto_disable', 20 );

2) If most pages you do want this functionality and just a few pages you don't:

/**
 * Disable My Effecto Plugin emoticons
 * Whenever conditions are met
 *
 * @return void
 */
function theme_myeffecto_disable() {

    // $showreactions set somewhere?

    if( ! $showreactions ) { // IF NOT show reactions, remove filter
        remove_filter( 'the_content', 'echoEndUserPlugin' );
    }

}
add_action( 'init', 'theme_myeffecto_disable', 20 );

We use the init hook since it fires after the hook has been added but before the_content actually runs. You would add this to your functions.php file or as a separate plugin.

I'm not familiar with the plugin but they also have an option mye_plugin_visib which they check for a few times you may also be able to set to false, but updating options constantly is not an optimal choice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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