# Flush Permalinks From the Admin Bar

> Adds a "Flush permalinks" link to the admin bar for administrators that rebuilds the rewrite rules in one click, handy after registering post types or custom rewrite rules.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: permalinks, rewrite-rules, admin-bar
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/debug-flush-permalinks-admin-bar/

## Code

```php
add_action( 'admin_bar_menu', function ( $admin_bar ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    $admin_bar->add_node( array(
        'id'     => 'wpide-flush-rewrites',
        'parent' => 'site-name',
        'title'  => 'Flush permalinks',
        'href'   => wp_nonce_url( admin_url( 'admin-post.php?action=wpide_flush_rewrites' ), 'wpide_flush_rewrites' ),
    ) );
}, 100 );

add_action( 'admin_post_wpide_flush_rewrites', function () {
    if ( ! current_user_can( 'manage_options' ) ) {
        wp_die( 'Not allowed.', 403 );
    }
    check_admin_referer( 'wpide_flush_rewrites' );

    flush_rewrite_rules();

    wp_safe_redirect( add_query_arg( 'wpide_flushed', 1, wp_get_referer() ? wp_get_referer() : admin_url() ) );
    exit;
} );

add_action( 'admin_notices', function () {
    if ( isset( $_GET['wpide_flushed'] ) && current_user_can( 'manage_options' ) ) {
        echo '<div class="notice notice-success is-dismissible"><p>Permalinks flushed.</p></div>';
    }
} );
```

## Notes

Same effect as saving Settings > Permalinks; the link is protected with a nonce.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Flush Permalinks From the Admin Bar" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
