Add specific word to default page permalink

Right now I am working on one of my client’s project. Its all about amazon product display.
My client wants me to change the permalinks of all posts, pages, serch results, archive pages, categorypages, all custom post type pages.

I am very new to Rewrite API. I have read the documentation provide on wordpress codex here https://codex.wordpress.org/Function_Reference/WP_Rewrite and here https://codex.wordpress.org/Rewrite_API as well as on the interne but can’t able to make the things clear.

Read More

Can anyone help me to generate custom permalinks for my pages ?

Right now, Page url looks like http://mysite.com/?page_id=2 if its default permalink and http://mysite.com/sample-page/ if its post name permalink.

I wants the page url looks like http://mysite.com/info/sample-page.

Here info is static word I want to be added to my page url.

How can I achieve this ? Can anyone help me out in this situation ? I have already wasted my 2 days in this issue and I am sure its really simple for the one who already worked with this.

Quick help much appreciated.

Thank You,
Aezaz

Related posts

Leave a Reply

1 comment

  1. There might be better ways using filters or apache/nginx rewrites, but here are two ideas to consider from the admin UI point of view (untested):

    Idea 1:

    You can always visit /wp-admin/options-general.php change the whole the site url:

    siteurl

    but I don’t think you’re looking for that, since this will also change the home url.

    Idea 2:

    You might therefore visit /wp-admin/options-permalink.php and try the following:

    rewrite

    to start with.

    Idea 3:

    Regarding the pages you could try to create a parent page with the info slug.

    This will not cover everything you mentioned, but hopefully this help you along the way.

    Update:

    Here’s something you could try to explore further (I’m not sure this even works):

    add_filter( 'rewrite_rules_array', 'my_rewrites' );
    
    function my_rewrites( $rules )
    {
        $newrules = array();
        foreach ( $rules as $rule => $rewrite )
        {
            if( '(' !==  substr( $rule, 0, 1 ) )
                $rule = 'info/' . $rule;
    
            unset( $rules[$rule] );
            $newrules[$rule] = $rules[$rule];
        }
        return $newrules;
    }
    

    You need to flush the rewrite rules, but you also need to modify the links trough the filters: post_link, term_link, page_link, tag_link, date_link, … etc.

    So you could try something like:

    // expand this to your needs, but there most be a single filter available instead?
    $items = array( 'post', 'page', 'date', 'tag', 'term', 'year', 'month' ); 
    
    foreach( $items as $item )
    {
        add_filter( $item . '_link', 'my_link', 99, 2 );
    }
    
    function my_link( $permalink, $post ) 
    {
       $permalink = str_replace( get_site_url(), get_site_url() . '/info',  $permalink );
        return $permalink;
    }
    

    I guess there are better hooks available and just better ways to try?

    This is just what comes first to mind, so please check and modify it 😉