I am trying to redefine the properties of the default post type 'POST'. I'm trying with the function register_post_type_args.
I want to redefine the label of the post type from "article" to "blog" and i want to add the slug "blog" for this post type in his url (mysite/blog/my-post)
Here is his call in functions.php:
function post_to_blog ($args, $post_type) {
if ('post' !== $post_type) {
return $args;
}
$args ['label'] = 'Blog';
$args ['rewrite'] = array ('slug' => "blog", 'with_front' => true);
return $args;
}
add_filter ('register_post_type_args', 'post_to_blog', 1, 2);
The label property is correctly redefined. The label is changed in the back office. But the post slug is not taken into account. The url of my posts is still mysite/name-of-post and not mysite/blog/name-of-post
(I can't add the slug in settings / permalinks because I need to keep the default url type for other post types).
I think I do it with register_post_type_args but I don't understand why the slug is not taken into account. Do you have an explanation ?
EDIT :
Just out of curiosity, I tried to redefine the post with register_post_type. This is not the correct method, but with this solution, the URLs are correctly redefined.
register_post_type( 'post', array(
'label' => 'Blog',
'rewrite' => array('slug' => "blog/", 'with_front' => true),
));
if ('post'! == $post_type)should produce a parse error. If this is your actual code then your function is probably failing silently because your error reporting is turned off. Remove the superfluous spaceif ('post' !== $post_type)and try again. - MonkeyZeus