Hello
I am trying to create an SEO friendly URL structure for my website.
I an trying to have an URL witohut thr word Category and parent category name for example
I have the below category structure
Category 1
-category 2
-category 3
--category 4
By default my category structure is
for 1st level category
http://www.mysite.com/category/category-1
For second level category
http://www.mysite.com/category/category-3/category-4
What I am trying to achieve is a URL structure like below
for 1st level category
http://www.mysite.com/category-1.html
For second level category
http://www.mysite.com/category-4.html
Till now I have achieved is
For second level category
http://www.mysite.com/category-4
The code I am using is
add_filter( 'category_link', 'wpse7807_category_link', 10, 2 );
function wpse7807_category_link( $catlink, $category_id )
{
global $wp_rewrite;
$catlink = $wp_rewrite->get_category_permastruct();
if ( empty( $catlink ) ) {
$catlink = home_url('?cat=' . $category_id);
} else {
$category = &get_category( $category_id );
$category_nicename = $category->slug;
$catlink = str_replace( '%category%', $category_nicename, $catlink );
$catlink = home_url( user_trailingslashit( $catlink, 'category' ) );
}
return $catlink;
}
Please help me out in creating the desired structure
Thank in advance