I have 2 urls:

  • www.site.com/post1/
  • www.site.com/post1/?content=onepage

I have the following function that controls the layout of the post through the URL parameters in BOLD:

www.site.com/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"] )


        // 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 );


How to make the url www.site.com/post1/ and www.site.com/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.

  • Can you indent your code? It looks like you have nested functions, never nest function definitions like that
    – Tom J Nowell
    Aug 6, 2019 at 0:05
  • Thanks! I indented the code. Don't know enough to either agree or disagree on the nested functions
    – Discover
    Aug 6, 2019 at 0:21
  • Are you doing this just for a specific post (e.g. post with the slug post1 as in your example), or just any posts?
    – Sally CJ
    Aug 6, 2019 at 2:59
  • I want this to apply to all posts
    – Discover
    Aug 6, 2019 at 3:09
  • Not sure if the answer helps, but that's an example for single posts, but also supports URLs having the content=onepage query string.
    – Sally CJ
    Aug 6, 2019 at 3:36

1 Answer 1


I 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"] )

with this:

if( ! is_single() && ( empty( $_GET["content"] ) || "onepage" !== $_GET["content"] ) )

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?

  • 1
    Awesome! " ! is_single() && " part did the trick. Thanks!
    – Discover
    Aug 6, 2019 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.