DEV Community

Samcorp
Samcorp

Posted on

Custom Post Type 404 Errors in WordPress.

Description
Custom post type URLs return a 404 error.

Causes
Permalinks are not flushed after registering the custom post type.

Solution

  • Add the following function to functions.php to flush permalinks:
function custom_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action('after_switch_theme', 'custom_flush_rewrite_rules');
Enter fullscreen mode Exit fullscreen mode
  • Visit Settings → Permalinks and click "Save Changes."

WordPress development services to build custom websites that are fast, secure, and easy to manage. From creating themes and plugins to optimizing performance, we ensure your website meets your business needs. Get a professional, user-friendly site that stands out.

Top comments (0)