How add .html in category url using hooks: WordPress


Hello Everyone,

If you want to add the .html in category page url without using any plugin then just add my code in your function file

https://raghunathgurjar.wordpress.com/mycategory.html

function add_before_and_after_rewrite() { 
    add_rewrite_tag("%cat_id%", '([^/]*)'); 
    /*add_rewrite_tag("%video_src%", '([^/]*)'); 
    add_rewrite_tag("%video_title%", '([^/]*)');*/ 
     
    // Before And After 
   //add_rewrite_rule('services.html', 'index.php?category_name=services', 'top'); 
   //add_rewrite_rule('services.html', 'index.php??cat=8', 'top'); 
    $cur_cat_id = get_cat_ID( single_cat_title("",false) ); 
    $category = &get_category($cur_cat_id); 
   //$slug =$category->slug; 
 
  add_rewrite_rule('uncategorized.html?$', 'index.php?cat=1', 'top'); 
     
  } 
  add_action( 'init', 'add_before_and_after_rewrite' );

Screenshot-1

Enjoy Code! | Raghunath Blog

Advertisements

Sr. Software Engineer

Tagged with: , , , ,
Posted in Wordpress
2 comments on “How add .html in category url using hooks: WordPress
  1. MikSco says:

    It’s possibile to use this with pages?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: