Ultimate Tag Warrior fix for WordPress 2.2.1

Jul 24, 2007 I Coding.

I've just installed WP 2.2.1 and had some problems with pretty URLs...

So I've played a bit (note that it's my first contact with WP so I'm not sure if my method is good) with the code...
Well... stop talking... here's my solution:

First of all: fix .htaccess...

My .htaccess file contents:

CODE:
  1. # BEGIN WordPress
  2.  
  3. RewriteEngine On
  4. RewriteBase /# Basic tag requests: "tag/TAGNAME" => "index.php?tag=TAGNAME"
  5. RewriteRule ^tag/?(.*)$ /index.php?tag=$1 [L]
  6. RewriteRule ^tag/?(.*)/$ /index.php?tag=$1 [L]
  7.  
  8. # Multipage requests: "tag/TAGNAME/page/N" => "index.php?tag=TAGNAME&paged=N"
  9. RewriteRule ^tag/?(.*)/page/?(.*)$ /index.php?tag=$1&paged=$2 [L]
  10. RewriteRule ^tag/?(.*)/page/?(.*)/$ /index.php?tag=$1&paged=$2 [L]
  11.  
  12. # Tag feeds: "tag/TAGNAME/rss" => "wp-rss.php?tag=TAGNAME"
  13. # "tag/TAGNAME/atom" => "wp-atom.php?tag=TAGNAME"
  14. RewriteRule ^tag/?(.*)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?tag=$1&feed=$2 [L]
  15.  
  16. RewriteCond %{REQUEST_FILENAME} !-f
  17. RewriteCond %{REQUEST_FILENAME} !-d
  18. RewriteRule . /index.php [L]
  19.  
  20. # END WordPress

My second problem was that I wanted to use /category/postname as permalink so the link /tag/tagname was detected as category "tag" and postname "tagname" by WP engine...
To fix this issue you need to edit ultimate-tag-warrior.php (I've use single-file release).

Find "ultimate_rewrite_rules" function (near 1550 line). Replace it with this one:

PHP:
  1. function ultimate_rewrite_rules($rules) {
  2. if(get_option("utw_use_pretty_urls") == "yes") {
  3. $baseurl = get_option("utw_base_url");
  4. $rules_tmp = array();
  5.  
  6. global $wp_rewrite;
  7.  
  8. $tagbase = substr($baseurl, 1, strlen($baseurl) - 2);
  9. $wp_rewrite->add_rewrite_tag('%tag%', '(.*)', 'tag=');
  10.  
  11. // without trailing slash
  12. $rules_tmp += $wp_rewrite->generate_rewrite_rules($baseurl . '%tag%');
  13. // with trailing slash
  14. $rules_tmp += $wp_rewrite->generate_rewrite_rules($baseurl . '%tag%/');
  15.  
  16. $rules = array_merge($rules_tmp, $rules);
  17. }
  18. return $rules;
  19. }

Now make your .htaccess NOT writable (chmod 644).
Then goto Admin->Options->Permalink and click "Update Permalink Structure" - this will rebuild internal rewrite rules...

I want to say again: this is my first contact with WordPress code. Just want to help you.

3 responses so far, say something?

  1. How to use UltimateTagWarrior in WordPress 2.2.1 : XianSi ’s Blog Says:

    [...] http://quark.qpsmod.net/coding/ultimate-tag-warrior-fix-for-wordpress-221 [...]

  2. How to use UltimateTagWarrior in WordPress 2.2.1 : XianSi Blog Says:

    [...] http://quark.qpsmod.net/coding/ultimate-tag-warrior-fix-for-wordpress-221 [...]

  3. XianSi ’s Blog » Blog Archive » How to use UltimateTagWarrior in WordPress 2.2.1 Says:

    [...] http://quark.qpsmod.net/coding/ultimate-tag-warrior-fix-for-wordpress-221 [...]

Leave a Reply