Duplicate ‘the_content’ filters

When outputting certain content, it’s useful for it to retain the features of WordPress’ the_content() function. Namely, that paragraphs are automatically generated (wpautop), shortcodes are run, and oEmbed converts certain links to rich media (ex: Youtube video link becomes embedded video).

You could do this by wrapping your content in apply_filters( 'the_content', $my_field );, but some plugins use the 'the_content' filter to add their own functionality to the main post content. You might end up with sharing links or some other unwanted feature on your content.

I create my own filter, 'ea_the_content', to which I attach all the functions I want. I can then use apply_filters( 'ea_the_content', $my_field ) without worrying about another plugin using the filter.

<?php
/**
* Duplicate 'the_content' filters
*
* @author Bill Erickson
* @link http://www.billerickson.net/code/duplicate-the_content-filters/
*/
global $wp_embed;
add_filter( 'ea_the_content', array( $wp_embed, 'run_shortcode' ), 8 );
add_filter( 'ea_the_content', array( $wp_embed, 'autoembed' ), 8 );
add_filter( 'ea_the_content', 'wptexturize' );
add_filter( 'ea_the_content', 'convert_chars' );
add_filter( 'ea_the_content', 'wpautop' );
add_filter( 'ea_the_content', 'shortcode_unautop' );
add_filter( 'ea_the_content', 'do_shortcode' );
view raw functions.php hosted with ❤ by GitHub
Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk