• I have created a WordPress page with name: shows. Now I want to add custom query var to that page’s URL but get 404 error.

    example.com/shows/test-var/

    function custom_rewrite_tag() {
        add_rewrite_tag('%animation%', '([^&]+)');
    }
    add_action('init', 'custom_rewrite_tag', 10, 0);
    
    function custom_rewrite_rule() {
        add_rewrite_rule('^shows/([^/]*)/([^/]*)/?', 'index.php?pagename=$matches[1]&animation=$matches[2]', 'top');
        flush_rewrite_rules();
    }
    add_action('init', 'custom_rewrite_rule', 10, 0);

    Can everyone help me? Thanks a lot.

  • The topic ‘Add custom query var to exists WordPress page get 404’ is closed to new replies.