Is there a way to show the category name in the URL of a post which is in a specific category? I.e:
I have a site which have a blog and two categories, blog and resources; right now this blog have the setting of only show the post name in the url (blabla/postname) so, all post follow this rule. But now, I have to enable a way for the resources posts show the category name (resources) in the URL, something like this: blabla/resources/postname, and having this two settings living side by side.
Blog must remain blog/postname, Resources should be blog/resources/postname
Thanks!
Is there a way to show the category name in the URL of a post which is in a specific category? I.e:
I have a site which have a blog and two categories, blog and resources; right now this blog have the setting of only show the post name in the url (blabla/postname) so, all post follow this rule. But now, I have to enable a way for the resources posts show the category name (resources) in the URL, something like this: blabla/resources/postname, and having this two settings living side by side.
Blog must remain blog/postname, Resources should be blog/resources/postname
Thanks!
Share Improve this question edited Nov 6, 2019 at 20:43 fuxia♦ 107k39 gold badges255 silver badges461 bronze badges asked Nov 6, 2019 at 20:15 Erick AcevedoErick Acevedo 11 bronze badge1 Answer
Reset to default 1The easiest way would be to create a custom post type with an archive.
<?php
register_post_type('resource',
array(
// Enable Core Categories and Tags
'taxonomies' => array('category', 'post_tag'),
// Enable in REST API so it works with the Block Editor
'show_in_rest' => true,
'label' => 'Resources',
'public' => true,
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions'),
// Archive URL will be example/resources
'has_archive' => 'resources',
// Posts will be at example/resources/postname
'rewrite' => array('slug' => 'resources')
)
);
?>
This will create the post type itself. Then, you can go into the database and change their post_type
from post
to resource
- or you could create PHP code to do this for you if you're not comfortable editing directly in the database.