Home Wp Tricks Rewrite wordpress post url working example

Rewrite wordpress post url working example

by therichpost
0 comment
How to add custom meta title and meta description in Wordpress?

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.


Thank you

You may also like

Leave a Comment

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