Can I add content before post content without usin

2019-08-17 06:39发布

问题:

I am adding filter to add embed before post content, but don't want add to other places where called apply_filters("the_content").

So i need add embed before(after) post content without "the_content" filter hook.

add_filter('the_content', 'embed_on_post');

回答1:

if you want to filter only a certain type or such, you can add your verification inside your filter function:

source: wordpress documentation

add_filter( 'the_content', 'my_function' ); 

function my_function( $content ) {
    //for a single post
    if (is_singular('post')) {
        /* do whant you want */
    }

    //or also (works for posts except attachments and pages)
    if (is_single()){

    }

    return $content;
}


标签: wordpress