0

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.com/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.com/resources/postname, and having this two settings living side by side.

Blog must remain blog.com/postname, Resources should be blog.com/resources/postname

Thanks!

1

The 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.com/resources
        'has_archive'       => 'resources',
        // Posts will be at example.com/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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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