Skip to main content

Filter The Content

By April 11, 2020No Comments

I have found it incredibly useful to hook into the_content when prepending or appending things to the main content area of a WordPress website!

add_filter( 'the_content', function( $content ) {
$ACF = get_field('acf_field');
$a_shortcode = do_shortcode( '[contact-form-7 id="1" title="CF7 Form!"]' );
$post_meta = get_post_meta( get_the_ID(), 'key', true )
if( ! is_front_page() && $acf == 1 ) {
return $content.$a_shortcode.$post_meta;
} else {
return $content;
}, 0);

This is just for example… I can output Advanced Custom Fields, Shortcodes (like Contact Form 7 forms) or regular old custom fields / post meta and use conditions like if ACF exists on any page except the front page etc. Very useful!

Contact us to learn more about Adopt the Web for your business

Author Jarod Thornton

More posts by Jarod Thornton