How to flush WP permalinks

If your site us unexpectedly taking you to non existing pages or to the wrong page it might be time to resave or flush permalinks. Permalinks that are internal connections between the slug (page url) and the page content. Here are 3 ways to flush Permalinks in WordPress

  1. In WordPress Dashboard go to Settings ->Permalinks and click Save Changes.

2. Use WPCLI – this is a command WordPress Command Line interface often available when you log into your site via ssh. cd to the directory where your site is located and run this command:

wp rewrite flush

3. In the code – this can a part of a plugin code or a cron job script.

flush_rewrite_rules();

OR

global $wp_rewrite;
$wp_rewrite->flush_rules();

You can also check the content of the permalinks array in the WordPress database by running this code:

echo "<pre>";
var_export(get_option('rewrite_rules' ));
echo "</pre>";