我有2个URL:
www.site。com/post1/li>www.site。com/post1/?content=onepage我有以下功能,可以通过中的URL参数控制帖子的布局BOLD:
www.site。com/post1/?content=onepage 激活以下功能:
function onepage(){
// condition(s) if you need to decide not to disabling shortcode(s)
if( empty( $_GET["content"] ) || "onepage" !== $_GET["content"] )
return;
// Condition(s) at top are not met, we can remove the shortcode(s)
function remove_shotcode($content) {
return str_replace(\'[/shortcode1]\', \'\', $content);
return str_replace(\'[shortcode2]\', \'\', $content);
}
add_filter( \'the_content\', \'remove_shotcode\', 6);
/**
* Ignore the <!--nextpage--> for content pagination.
*
* @see http://wordpress.stackexchange.com/a/183587/26350
*/
add_action( \'the_post\', function( $post )
{
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 );
}
add_action(\'wp\',\'onepage\');
如何创建urlwww.site.com/post1/ 和www.site.com/post1/?content=onepage 默认情况下加载相同的函数。我认为它只需要一个简单的条件:
这是参数content 设置为onepage
if( empty( $_GET["content"] ) || "onepage" !== $_GET["content"] )