search

Home  >  Q&A  >  body text

Show only specific categories in page permalinks

I tried asking this question in the Wordpress Devlopment network without success, I tried showing only specific categories in the permalinks of the page.

Now permalink structure for all pages and posts (POST type)

example.com/the-post-title/

This works for all my post and page categories, I want all categories to look like this But I want this category "Downloads"

when I select it to display on these pages

example.com/downloads/the-post-title/

Can anyone help me with how to use php code or something else for this specific category.

I tried some plugins and searched on the web but didn't find anything relevant

P粉329425839P粉329425839454 days ago781

reply all(2)I'll reply

  • P粉127901279

    P粉1279012792023-09-17 11:34:21

    You can use https://www.tiny.cloud/docs/plugins /opensource/link/ This plugin is used to customize your links.

    reply
    0
  • P粉451614834

    P粉4516148342023-09-17 00:28:15

    You will need to define custom rewrite rules to capture requests for /downloads/ and direct them correctly. To do this, use add_rewite_rule() to match existing rewrite rules for posts and pages.

    Then use post_linkfilter to change the URL of the post to include /downloads/.

    pseudocode:

    add_action( 'init', static function () {
        add_rewrite_rule( ... );
    } );
    
    add_filter( 'post_link', static function ( $permalink, $post ) {
        // add test for post is in category
        return sprintf( '/downloads/%s', $post->post_name );
    }, 10, 2 );
    

    reply
    0
  • Cancelreply