Support » Fixing WordPress » How to print rewrite rules?

  • I’ve added a menu page and user var_dump function to print $wp_rewrite object but rules is set to null. How can I print rules? I think that admin_menu hook is called early and rules are not set yet.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Christian Chung

    (@christian1012)

    did you call global $wp_rewrite; ?

    There are also plugins like the rewrite rules inspector. http://wordpress.org/plugins/rewrite-rules-inspector/

    Christian Chung

    (@christian1012)

    Also, the init hook would probably be best.

    Yes, I called it. This is the code:

    add_action('admin_menu', 'gp_call_add_rewrite_page');
    
    function gp_call_add_rewrite_page() {
        add_menu_page('Rewrite Page', 'Rewrite Page', 'manage_options', __FILE__, 'gp_add_rewrite_page', 'dashicons-edit');
    }
    
    function gp_add_rewrite_page() {
        ?>
        <div class="wrap">
            <h2>Rewrite Page</h2>
            <?php
            global $wp_rewrite;
            var_dump($wp_rewrite);
            ?>
        </div>
        <?php
    }

    I set permalinks to /%postname%.html in Settings > Permalinks

    Christian Chung

    (@christian1012)

    I just tested, code works for me. Flush your rules perhaps.

    I tried first time on 3.9-beta3 version so I tried also on 3.8.1 version but I can’t see any rules also flushing rules.

    I found a solution, I don’t know if it is the best solution but it works.
    I read directly from database using this line of code:

    $rewrite_rules = get_option( 'rewrite_rules' );

    and then I loop the array.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to print rewrite rules?’ is closed to new replies.