WordPress.org

Forums

add_rewrite_rule. Please help!!! (1 post)

  1. emmolos
    Member
    Posted 1 year ago #

    I want to rewrite the URL below:

    FROM:

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

    TO:

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

    Details below:

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

    My links on this page points to: http://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!!!

Topic Closed

This topic has been closed to new replies.

About this Topic