Back to Top

How to add new URL rewrite rule in WordPress?

To add new URL rewrite rule in Wordpress

Nowadays URL rewriting is most important for any kind of website. URL rewriting is to create a search engine friendly urls. URL rewrite means to remove ? and & from url query string and make it pretty.

WordPress provide permalink setting to use search engine friendly urls. Also,Wordpress stores rewrite rules into the options table of the database. But sometimes you want to add new rewrite urls which is not exists.

First of all,enable the permalink setting to default from wordpress admin panel and write following code into your htaccess.

You can add rewrite url using add_rewrite_rule() function in WordPress.The function allows three parameters. First parameter is the regex that will match with the rule and the second parameter is the rewritten URL whereas the third is used to define that where to place the rule at the top or bottom in database option.

Let’s look into the function:

You can access variable on page using get_query_var function like shown as below:

Add above code into your theme’s functions.php file or your plugin’s main file.This code will create new tag and rule for you.And flush_rewrite_rules() function will completely refresh the rewrite rules and fix if any problems with redirection.

So,We are done here. Add rule when require and enjoy 🙂
If you have any query or question,tell us in the comment section :). Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Most Popular Posts

What is Parent:: and Self:: in PHP

Posted on 6 years ago

Bhumi

How to detect browser in Joomla

Posted on 5 years ago

Bhumi

Django Tutorial for beginners

Posted on 1 year ago

Bhumi

Overview of ECMAScript 6 new Features

Updated 18 years ago

Bhumi

Getting started with Amazon Web Services

Updated 18 years ago

Bhumi

Facade implementation in Laravel

Updated 18 years ago

Bhumi

The Reader’s Poll – June 2015

Posted on 2 years ago

Bhumi

The Reader’s Poll – August 2014

Posted on 3 years ago

Bhumi

The Reader’s Poll – June 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – May 2014

Posted on 3 years ago

Bhumi

The Readers’ Poll – August 2013

Posted on 4 years ago

Bhumi