admin管理员组文章数量:1417034
I have 2 urls:
- www.site/post1/
- www.site/post1/?content=onepage
I have the following function that controls the layout of the post through the URL parameters in BOLD:
www.site/post1/?content=onepage activates the function below:
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
*/
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');
How to make the url www.site/post1/ and www.site/post1/?content=onepage load the same function by default.
I think it just need a simple condition for:
This one is for parameter content set to onepage
if( empty( $_GET["content"] ) || "onepage" !== $_GET["content"] )
And another for if no url parameters set.
I have 2 urls:
- www.site/post1/
- www.site/post1/?content=onepage
I have the following function that controls the layout of the post through the URL parameters in BOLD:
www.site/post1/?content=onepage activates the function below:
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/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');
How to make the url www.site/post1/ and www.site/post1/?content=onepage load the same function by default.
I think it just need a simple condition for:
This one is for parameter content set to onepage
if( empty( $_GET["content"] ) || "onepage" !== $_GET["content"] )
And another for if no url parameters set.
Share Improve this question edited Aug 6, 2019 at 2:49 Discover asked Aug 5, 2019 at 23:08 DiscoverDiscover 331 gold badge1 silver badge6 bronze badges 5 |1 Answer
Reset to default 0I want this to apply to all posts
First off, making the content
query string defaults to onepage
is actually equivalent to enabling the onepage()
for all URLs/pages.
And for example to enable it by default on single post pages only (for any post types), then you can replace this:
if( empty( $_GET["content"] ) || "onepage" !== $_GET["content"] )
return;
with this:
if( ! is_single() && ( empty( $_GET["content"] ) || "onepage" !== $_GET["content"] ) )
return;
which means the onepage()
would also be applied on pages/URLs where the content=onepage
presents in the query string.
Check the developer docs for other conditional tags like is_singular()
.
Does that answer your question?
本文标签: functionsSet URL Parameter Post Layout As Default
版权声明:本文标题:functions - Set URL Parameter Post Layout As Default 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745266843a2650653.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
post1
as in your example), or just any posts? – Sally CJ Commented Aug 6, 2019 at 2:59content=onepage
query string. – Sally CJ Commented Aug 6, 2019 at 3:36