Rewrite category wordpress

Is it possible to rewrite only one category ?

I have a category "Photos" and just for this category.

I just want to rewrite it from /category/photos to /photos

Answers


You can do it with WP Rewrite API. Add this to functions.php

add_action('init', 'register_rewrites');
function register_rewrites() {
   add_rewrite_rule('^photos$', 'index.php?category_name=photos','top');
}

Remember to reload your rewrite settings: go to Settings -> Permalinks and click on Save button - no changes needed.


The Yoast SEO plugin has this function build in, I recommend this plugin in general. no-category-base-wpml only does this If you don't want to install a plugin for this. Around the web there are many tutorials which do this:

Too enable this for just one category I would advise the following:

  1. create a page called photos.
  2. create a theme template page for this photo page
  3. In is set up a new query_posts* getting the category 'photos'
  4. Include the category.php file.
  5. assign that template to the photo page.

Not tested but should work. Because the page has the correct URL and should include the category. Questions, aks.

*query_posts is bad for performance if you want to do it totally correct use the pre_get_posts filter. It's requires more knowledge.


Need Your Help

git: share the work of merging two branches

git merge conflict

I want to merge to very diverged Git branches together. That will be a lot of work because they have several hundreds conflicts.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.