skip to Main Content

I tried to ask this question in the WordPress Devlopment network with no success, I’m trying to display specific category only in permalinks for pages.

Right now the permalinks structure (POST Type) for All pages and post

example.com/the-post-title/

this is work for all my categories of post and pages and i want this for all categories look like
but i want this category ‘downloads’ when i select on those pages its show look like

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

anyone help me out how to do it with php code or something else for this specific categories.

i try some plugin and search on web but not found anythinf related

2

Answers


  1. You can use https://www.tiny.cloud/docs/plugins/opensource/link/ this plugin for customizing your link.

    Login or Signup to reply.
  2. You will want to define a custom rewrite rule, to capture requests to /downloads/ and direct them correctly. To do so, use add_rewite_rule() to match the existing rewrite rule for posts and pages.

    Then use the post_link filter to change the post’s URL to include /downloads/.

    Pseudo-code:

    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 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search