WordPress

How to Flush Permalinks on WordPress?

· Updated Sep 8, 2024 · 3 min read

Permalinks are the permanent URLs to your individual posts, pages, and other content on your WordPress site. Sometimes, you may need to refresh or “flush” these permalinks to resolve issues with broken links or changes in URL structure. In this article, we’ll walk you through the process of flushing permalinks on WordPress.

Flushing permalinks can resolve several common issues, such as:

Flushing permalinks is a simple yet effective troubleshooting step that can often fix these issues.

The easiest way to flush permalinks is through the WordPress dashboard. Follow these steps:

  1. Log in to your WordPress admin area.

  2. Navigate to Settings > Permalinks.

  3. Scroll to the bottom of the page and click Save Changes.

You don’t need to make any changes to your settings. Simply clicking the Save Changes button will refresh your permalinks.

In some cases, you might need to flush permalinks programmatically, especially if you’re developing a theme or plugin. Here’s how you can do it:

Using PHP Code

Add the following code snippet to your theme’s functions.php file or a custom plugin:

function custom_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'custom_flush_rewrite_rules' );

This code will flush the rewrite rules when your theme is activated. You can also trigger this function at other times by hooking into different WordPress actions.

Via WP-CLI

WP-CLI is a command-line interface for WordPress. If you have access to your hosting server via SSH, you can flush permalinks with a simple command:

wp rewrite flush

This command is especially useful for automated scripts and deployments.

Conclusion

Flushing permalinks is a straightforward yet powerful tool for maintaining your WordPress site’s health. Whether you’re experiencing 404 errors, changing URL structures, or developing new features, knowing how to flush permalinks can save you a lot of headaches.

By following the steps outlined above, you can easily flush permalinks via the WordPress dashboard, programmatically, or using WP-CLI. Keep this guide handy for the next time you need to troubleshoot your site’s URLs.

If you have any questions or run into issues, feel free to leave a comment below or contact us for further assistance!

Shameem Reza
Written by Shameem Reza

I am a Happiness Engineer at Automattic, helping merchants turn WooCommerce chaos into calm with clear solutions and simple technical breakdowns.

Enjoyed reading this?

This site stays ad-free and independent. If something here saved you time or taught you something new, a coffee goes a long way.

Buy me a coffee ☕
Keep reading