Clik here to view.

So you have created a theme and registered a custom post type (CPT). Now you go and install a social share plugin and you want to have it only on posts and pages but the plugin doesn’t have any option to disable it on CPT. So, now you have your theme showing all those custom html or share button all over the site with all post types. It could be useful in some cases but sometime you might not want that.
There Is A Couple Of Approaches You Could Think Of:
- Go through the plugin file and find the filter name then use
remove_filter()
to remove it. Its a efficient method if you know you are going to use a specific plugin for sharing. But in case you are creating the wordpress theme for your client or for sale nigher you have any control nor there is now way to know what plugin your users might use. - Creating a function of your own that skips
the_content
filter (this is where all plugins adds the extra html).
Check the_content() Filter:
You can use the global $wp_filter
array to check for callbacks on each filter. Here is for example a code snippet that prints out all the callbacks on the the_content
filter in the footer part of your theme (from WPSE).
add_action('wp_footer',function(){ global $wp_filter; printf('<pre>%s</pre>',print_r( $wp_filter['the_content'],true)); });
[10] => Array ( [wptexturize] => Array ( [function] => wptexturize [accepted_args] => 1 ) [convert_smilies] => Array ( [function] => convert_smilies [accepted_args] => 1 ) [convert_chars] => Array ( [function] => convert_chars [accepted_args] => 1 ) [wpautop] => Array ( [function] => wpautop [accepted_args] => 1 ) [shortcode_unautop] => Array ( [function] => shortcode_unautop [accepted_args] => 1 ) [prepend_attachment] => Array ( [function] => prepend_attachment [accepted_args] => 1 ) )
This gives us a rough idea what callback functions are in use when the_content
filter is called. We will apply those filter in our custom function to make it as functional as the_content() function.
the_content() Function
Now lets have a look at the_content() function and see how it looks.
function the_content($more_link_text = null, $stripteaser = false) { $content = get_the_content($more_link_text, $stripteaser); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; }
Lets Create Our Custom Function
We will call it custom_the_content() or whatever you like. Just make sure you use a unique name so it doesn’t conflicted with core function or plugin functions.
if(!function_exists('custom_the_content')){ function custom_the_content($more_link_text = null, $stripteaser = false){ $content = get_the_content($more_link_text, $stripteaser); $content = wptexturize($content); $content = convert_smilies($content); $content = convert_chars($content); $content = wpautop($content); $content = shortcode_unautop($content); $content = do_shortcode($content); // I will skip prepend_attachment as I think I won't need it $content = str_replace(']]>', ']]>', $content); echo $content; } }
Now you can use your custom function anywhere in the theme which will work as well as the_content
but won’t be affected by any plugins :). Worth mansion here there is another filter that other plugin might use is the_title
. You can work with it if you want to cover the whole ground. Let me know if you have any question.