如何获取WordPress帖子的默认内容?

时间:2015-10-13 02:55:55

标签: wordpress

有没有办法可以在WordPress帖子中获取the_content的默认输出?一些插件使用add_filter添加内容以添加他们想要的结果,如相关的帖子插件,他们在帖子内容的末尾添加结果。我想要发生的是获得WordPress核心的默认格式化功能,而无需其他插件的任何其他过滤器。

3 个答案:

答案 0 :(得分:1)

您可以使用删除过滤功能。

remove_filter( $tag, $function_to_remove, $priority );

有关详情,请参阅以下链接

https://codex.wordpress.org/Function_Reference/remove_filter

答案 1 :(得分:0)

您可以使用the_content过滤器本身来获取帖子对象或内容,您可以对其进行修改,也可以将其取消挂钩,然后根据您的要求再次将其挂钩。

如果我理解了你的要求,link会对你有所帮助,如果你需要不同的东西,请问我。

答案 2 :(得分:0)

伙计们感谢您回答我的问题我认为我得到了它但需要进行更多测试。我所做的是我复制了关于WordPress的the_content()功能如何工作的过程。根据我的研究,您可以在此链接上看到来自WordPress核心的10个默认过滤器:read here

我刚从WordPress创建了自己的函数,如the_content(),并将默认过滤器应用于我自己的函数。将此代码放在functions.php

if(!function_exists(default_post_content)){
    function default_post_content( $more_link_text = null, $strip_teaser = false) {
        $content = get_the_content( $more_link_text, $strip_teaser );
        $content = apply_filters( 'default_post_content', $content );
        $content = str_replace( ']]>', ']]>', $content );

        echo do_shortcode($content);
    }

    add_filter( 'default_post_content', array( $wp_embed, 'run_shortcode' ), 8 );
    add_filter( 'default_post_content', array( $wp_embed, 'autoembed'), 8 );
    add_filter ( 'default_post_content', 'wptexturize');
    add_filter ( 'default_post_content', 'convert_smilies');
    add_filter ( 'default_post_content', 'convert_chars');
    add_filter ( 'default_post_content', 'wpautop');
    add_filter ( 'default_post_content', 'shortcode_unautop');
    add_filter ( 'default_post_content', 'prepend_attachment'); 
}

然后例如在您的单页模板(single.php)中,而不是使用通常的the_content,我可以使用我的函数default_post_content();。现在,我不需要担心任何为the_content()功能创建额外数据的插件。