Custom Fancy and SEO friendly Urls in WordPress

I have searched a lot for this wordpress tricks or hacks to make my own Custom Fancy and SEO Friendly Urls, mostly I failed. Tried by changing or modifying .htaccess RewriteRule method and with custom wordpress WP Rewrite API function add_rewrite_rule(). After googling with this new WP Rewrite API method I found this article “Custom rewrite rules in WordPress (add_rewrite_rule and add_rewrite_tag)” by Dan but some how that dint worked to me.

So thought there might be some other alternative solution to do this job, started scrolling through the support forms of wordpress, then I found a thread “Correct usage of add_rewrite in plugin” by bennybobw which gives an another alternative method to achieve this custom SEO friendly urls.

Custom Fancy and SEO friendly Urls in WordPress
Custom Fancy and SEO friendly Urls in WordPress

Here is the snippet which should be used either in your themes functions.php or into your custom wordpress plugin:

I tried the following snippet and I succeeded :)

function myvar_flush_rewrite() {
  global $wp_rewrite;
function myvar_vars($public_query_vars) {
    $public_query_vars[] = 'myvar';
    return $public_query_vars;
function myvar_add_rewrite_rules($wp_rewrite) {
  $new_rules = array(
     'video-buzz/(.+)' => 'index.php?pagename=video-buzz&myvar=' . $wp_rewrite->preg_index(1));
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
add_action('init', 'myvar_flush_rewrite');
add_filter('query_vars', 'myvar_vars');
add_action('generate_rewrite_rules', 'myvar_add_rewrite_rules');

I have used the above method to show my Video Buzz custom queried pages in short custom, fancy and SEO friendly urls.

Let me explain you in detail:

  1. I have created a custom template
  2. The template has some dynamic content which displays based on the custom query “myvar” passed like “”
  3. To make the above url as “” I have used the above action and filters to make the custom fancy and short urls – which are SEO friendly
  4. You can grab the custom query “myvar” value in your custom template or plugin with get_query_var() function as “get_query_var(‘myvar’)
  5. We are done :) – In this way you can have wordpress custom fancy and SEO friendly urls for your own custom plugin or template.

Just explore and let me know if you find and difficulties in implementing this, will try my best to help you.

Published by Sravan Kumar

A Creative Web Designer, Developer, User Interface and User Experience Expert.

Join the Conversation


  1. Pingback: Anonymous
  2. Pingback: Custom Fancy and SEO friendly Urls in Wordpress WittySparks | Wood TV Stand
  3. We are done – In this way you can have wordpress custom fancy and SEO friendly urls for your own custom plugin or template.

  4. i have been using WordPress for 2 years but i still dont know how to do SEO using WordPress, is there an SEO pluggin for WordPress?.

  5. WordPress is one of the most popular blogging platform available on the internet today.
    Many smart marketers have used WordPress to promote their business and products online.
    It’s extremely flexible and powerful.

    Other benefits of using WordPress to create your business website is that you don’t need to know a single html code.
    In fact, as long as you know how to use Microsoft Word processor such as MS Word, you would be able to use WordPress.

    It is nice to once and for all find a web site like this where the blogger is knowledgable.

Leave a comment

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

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

Thank you for sharing the article across social media. You can follow us in these paltforms to receive latest updates from WittySparks.

Send this to a friend