Wp Tricks

Rewrite wordpress post url working example

Views

Hello to all, welcome to therichpost.com. In this post, I will tell you, how to Rewrite wordpress post url working example.

Here I am introducing the new chapter of my blog and that is called Wp Tricks.

Now I come to this post, first I will tell you very short story behind this post. last few days ago, I was searching for changing WordPress Post URL and only with WordPress Hooks and I just want to add “blog” in between my WordPress Post URLs and I have done with below code.

Here is the working code and you need to add this into your theme’s functions.php file very carefully:

function filter_post_link($permalink, $post) {
    //Using only for post but can use for other posts types too
    if ($post->post_type == 'post')
     {  
         return 'blog'.$permalink; // this code will add blog in my post ulrs https://therichpost.com/blog/post-title

     }
}
add_filter('pre_post_link', 'filter_post_link', 10, 2);
 This will Filters the permalink structure for a post before token replacement occurs.

For Working, please check this video:

If you have any query related to this post then feel free to ask.

Jassa

Thank you

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL