1

When a plugin registers a post type and sets has_archive to true, is there a way to change it to be false? I don't want the plugin's post type to have an archive, but can't figure out how to turn it off.

A similar questions was asked here, but has no responses: Changing a custom post type "has_archive" after registered

1
  • 1
    When a post type is registered, rewrite rules are added to handle the archive if it's set to true. A few ideas - filter rewrite_rules_array to remove those rules, add an action to parse_request to force archive requests to 404, or remove the plugin's action that registers the post type and register it yourself with your own arguments (could be risky). I'm not sure what would be the best solution.
    – Milo
    Oct 23, 2015 at 4:37

1 Answer 1

2

The register_post_type_args filter (available from WordPress v4.4 on) will allow post type registration arguments to be changed:

function wpse206329_custom_post_type_args( $args, $post_type ) {
    if ( $post_type === "my_post_type" ) {
        $args['rewrite'] = false;
    }

    return $args;
}
add_filter( 'register_post_type_args', 'wpse206329_custom_post_type_args', 20, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.