Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

share|improve this question
    
What is "info" in mysite.com/info/sample-page? Functions it as an archive page? –  Robbert Apr 10 at 9:34
    
No, Its just static word(like prefix). I want to add it to only pages. Its just static word needs to be added in page url. –  Shaikh Aezaz Apr 10 at 10:00
    
Can anyone help me to solve this out ? Its very frustrating :( –  Shaikh Aezaz Apr 10 at 11:37
    
No one comes for help ? :( –  Shaikh Aezaz Apr 14 at 6:16

1 Answer 1

up vote 1 down vote accepted

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 ;-)

share|improve this answer
    
Thank you for answer. But... I don't want to do it from wordpress permalink UI, I want to use WordPress ReWrite API to do this because I am going to do this in 4-5 themes and client is preferring to use rewrite API. Please help :( –  Shaikh Aezaz Apr 10 at 12:42
    
Did you try the *_rewrite_rules filters? I'm not sure this is an easy task. I wonder if multisite setup would solve this, but I guess that's not what you're looking for ;-) –  birgire Apr 10 at 17:41
    
I tried working with rewrite_rules but the documentation is not enough for me to understand. :( No WordPress Experts here ? :( –  Shaikh Aezaz Apr 11 at 5:01
    
Someone help me please.. My project is near cancellation :'( –  Shaikh Aezaz Apr 14 at 10:08
    
@ShaikhAezaz Any luck with the updated answer? –  birgire Apr 14 at 17:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.