1

Old (non-Wordpress) URL structure:

"News" and "Gossip" are categories "Italy" and "Uk" are subcategories

https://example.com/news/italy
https://example.com/news/uk

https://example.com/gossip/italy
https://example.com/gossip/uk

New (Wordpress) URL structure:

Importing all the contents from the old db, the structure created isn't the same.

https://example.com/news/italy
https://example.com/news/uk-news

https://example.com/gossip/italy
https://example.com/gossip/uk-gossip

Is there a way to reproduce and preserve the old URL structure?

0

You won't be able to use regular Categories in WordPress because Categories must all have unique slugs.

However, you can still achieve this URL structure. You would need to create at least one custom post type. I would suggest keeping "News" category as regular Core Posts, and creating a Custom Post Type called "Gossip."

You can create this using your own custom plugin. Save this code as "create-gossip-cpt.php" within "/wp-content/plugins/create-gossip-cpt/":

<?php
/* Plugin Name: Create Gossip CPT */
// Run everything when the plugin is activated
register_activation_hook(__FILE__, 'wpse_361317_activation');
function wpse_361317_activation() {
    // (You may have to play around with the settings)
    register_post_type('gossip',
        array(
            // Plural, human-readable label for menu
            'label' => 'Gossip Articles',
            // Show in REST API must be true for the Block Editor
            'show_in_rest' => true,
            // Enable Title, Editor, and Excerpt
            'supports' => array('title', 'editor', 'excerpt'),
            // has_archive will create http://example.com/gossip/
            // much like a Post Category archive
            'has_archive' => 'gossip'
        )
    );
}
?>

This will give you the basic structure. You'll have a new "Gossip" item in wp-admin's left navigation window, similar to how you currently has "Posts".

Next you'll face a choice. You can either make this post type hierarchical, in which case you would have http://example.com/gossip/italy which would be a CPT itself. In this case, you would manually manage all the content. This might not be what you want, but the code to set this up is what's already above.

If you'd rather have that be an archive of all "Gossip" items that are assigned to a Gossip Category called "Italy," and automatically list all the related posts, you'll have to create that custom taxonomy, assign it to the CPT, and set up URL rewrites. Start here, and if you need help with the other bits, you'll likely find the code for the rest here on WPSE in answered questions.

| improve this answer | |
  • Thanks for your reply! The problem is that Gossip, News, Italy and Uk are only an example: I have a large amount of categories and subcategories to manage and I don't think your solution is usable in my case. Is there any other ideas? – Ale Mar 25 at 11:35
  • Your best bet is probably to keep the WP URL structure and add 301 redirects so search engines and visitors are sent to the new URLs. – WebElaine Mar 25 at 21:11

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.