0

I am using this code to insert custom content after title and before content. How can i limit it to only "post" not pages and custom post types.

function theme_slug_filter_the_content( $content ) {
$custom_content = 'YOUR CONTENT GOES HERE';
$custom_content .= $content;
return $custom_content;} add_filter( 'the_content', 'theme_slug_filter_the_content' );

1 Answer 1

1

You can check the post type of the current post via get_post_type:

function theme_slug_filter_the_content( $content ) {
    if( 'post' == get_post_type() ){
        $custom_content = 'YOUR CONTENT GOES HERE';
        return $custom_content . $content;
    }
    return $content;
}
add_filter( 'the_content', 'theme_slug_filter_the_content' );

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.