首页 > 解决方案 > 如何从 Wordpress 中的特定单页中删除标签?

问题描述

我正在尝试<!--nextpage-->从我的 single.php 内容文件中删除标签,但它会显示其他单个文件,如 single-post1.php 或 single-post2.php。我尝试使用 is_singular 函数,但是当它进入 if 条件时,它会全局重置所有内容,我该如何处理它的特定文件。

add_action( 'the_post', function( $post )
{

 if(is_singular() && 'post' == get_post_type() && 'post1' != get_post_type() && 'post2' != get_post_type() ){

    if ( false !== strpos( $post->post_content, '<!--nextpage-->' ) ) 
    {
        // Reset the global $pages:
        $GLOBALS['pages']     = [ $post->post_content ];

        // Reset the global $numpages:
        $GLOBALS['numpages']  = 0;

       // Reset the global $multipage:
        $GLOBALS['multipage'] = false;
    }
}

}, 99 );

谢谢你的帮助....

标签: phpwordpress

解决方案


推荐阅读