Custom Fancy and SEO friendly Urls in WordPress

This entry was posted in Programming and tagged , , . Bookmark the permalink.
Advertisement

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;
  $wp_rewrite->flush_rules();
}
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 “http://www.wittysparks.com/video-buzz/?myvar=sports”
  3. To make the above url as “http://www.wittysparks.com/video-buzz/sports/” 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.

Top Random Reads on the Web

  • Pingback: Anonymous

  • http://www.seoptimazer.com SEO pro

    Hmmmmmm
    Very interesting- I’ll check it asap

  • http://www.maheshkukreja.com Mahesh

    Thanx.. I needed this!

  • Pingback: Custom Fancy and SEO friendly Urls in Wordpress WittySparks | Wood TV Stand

  • http://bestseoweb.com yong wang

    We are done – In this way you can have wordpress custom fancy and SEO friendly urls for your own custom plugin or template.

  • http://www.arthritistreatmentlab.com Matt

    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?.

  • http://www.wittysparks.com admin

    @Matt – yes we have many – you can check this blog for list of Best SEO Plugins available for wordpress – http://mashable.com/2009/03/20/wordpress-seo-plugins/

  • André

    Perfect for me!!! Thanks.

  • http://www.dealzbydesign.com/pages/search-engine-optimization.html SEO Lexington KY

    Great point, mod rewrites are important for good SEO.

  • http://www.topranker.in Guest

    Thanks for great article. i really like to visit your website

  • http://seo2go.com.au/ Reariz from seo

    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.

  • http://security-wire.com/01/how-to-remove-disk-optimizer-fake-security-program.html remove disk optimizer

    You can customize your URL thru wp admin/

  • http://security-wire.com/01/how-to-remove-disk-optimizer-fake-security-program.html remove disk optimizer

    You can customize your URL thru wp admin/