• Hi ??
    I installed a plugin to add categories to Pages, as well as Posts, because I’d like to add a /category/ slug to a group of important pages so my team can easily track their performance in Google Analytics. However, there doesn’t seem to be an option to be able to add the /category/ slug in the URL of Pages, only Posts.

    Does anyone have any insight how I can add a new /category/ slug to a group of Pages? I’d be forever grateful. Thank you so much for any wisdom you might have!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Custom Taxonomy: First, ensure the plugin you installed successfully adds category taxonomy to your Pages. If it does, you’re halfway there. If not, you may need a different plugin or custom code in your theme’s functions.php file to register a category taxonomy for Pages.

    Permalinks: WordPress doesn’t natively support adding a category base to Pages, as it does with Posts. To achieve this, you will need to add custom rewrite rules. This can be complex and might require a developer’s assistance if you’re not comfortable with code. Here’s a basic outline of how you can do it:

    • Go to your theme’s functions.php file or use a site-specific plugin.
    • Use the add_rewrite_rule function to create a new URL structure for Pages. For example:
    • function add_category_base_to_pages() { add_rewrite_rule('^category/(.+)/?$', 'index.php?pagename=$matches[1]', 'top'); } add_action('init', 'add_category_base_to_pages');
    • This code is a simple example and may need to be adjusted based on your specific requirements.

    Update Permalinks: After adding the code, go to Settings > Permalinks in your WordPress dashboard and just click Save Changes to flush the rewrite rules. This step is crucial whenever you add or modify rewrite rules.

    Moderator bcworkz

    (@bcworkz)

    WP Provider correctly tells you how to get WP to properly handle a page request that includes a category parameter, but that alone will not cause WP to generate page URLs that have a category parameter.

    It’s possible that your page category plugin does this for you. In case it does not, use the “page_link” filter to cause page permalinks to be structured as desired.

    FWIW, you don’t actually need to save changes to flush old rewrite rules, simply loading the permalinks setting screen is enough.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding category slugs to URL of PAGES’ is closed to new replies.