• emmolos

    (@emmolos)


    I want to rewrite the URL below:

    FROM:

    https://example.com/test/portfolio/?pslug=plants

    TO:

    https://example.com/test/portfolio/plants

    Details below:

    With WordPress Permalink Settings set to “Post name”, my current portfolio URL is: https://example.com/test/portfolio/

    My links on this page points to: https://example.com/test/portfolio/?pslug=plants

    pslug is the custom parameter I added.

    my functions.php

    function add_query_vars($vars){
        $vars[] = "pslug";
        return $vars;
    }
    add_filter('query_vars', 'add_query_vars');
    
    function add_portfolio_rules() {
        add_rewrite_rule('portfolio/([^/]+)/?$', 'index.php?page_id=117&pslug=$matches[1]', 'top');
    }
    add_action('init', 'add_portfolio_rules');

    Please help!!! I have tried everything but nothing works.
    Thanks!!!

  • The topic ‘add_rewrite_rule. Please help!!!’ is closed to new replies.