Changing arguments for a post type “on the fly” by changing the global
at some random point in time is below ideal. When you look at register_post_type()
there is the register_post_type_args
filter.
Example on how to use it as a small (mu-)plugin:
<?php
/**
* Plugin Name: Change Post Type arguments for Post Type X
*/
add_filter( 'plugins_loaded', function() {
add_filter( 'register_post_type_args', function( Array $args, $post_type ) {
// Change nothing for all other post types
if ( 'your_post_type' !== $post_type )
return $args;
$args['rewrite'] => [
'with_front' => true,
'slug' => 'opinions',
];
return $args;
}, 20, 2 );
} );
In above example, the post type gets a /opinions
“front” prepended. Example resulting Url:
https://example.com/opinions/rewrites-are-cumbersome
To adjust the labels
, use the labels
array that you will find in above link and in all examples below (plus changing help tabs, update messages, etc.).
Your admin menu slugs and labels will adjust accordingly by themselves, fed by the labels
arguments you provided.