Turn Off the Archive Page of a Post Type
Removes the automatic archive page of a post type, for example when you build the listing yourself on a regular page with the same URL.
Opens WPIDE on
Code
// Post types without an archive page.
$wpide_no_archive_types = array( 'portfolio' );
add_filter( 'register_post_type_args', function ( $args, $post_type ) use ( $wpide_no_archive_types ) {
if ( in_array( $post_type, $wpide_no_archive_types, true ) ) {
$args['has_archive'] = false;
}
return $args;
}, 10, 2 );
Notes
Visit Settings > Permalinks once afterwards so a page with that slug can take over the URL.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.