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

2 Replies to “How add .html in category url using hooks: WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *