Give specific category its own permalink structure

Try these steps: Step #1: Replace this: add_action( ‘init’, ‘custom_rewrite_rules’ ); function custom_rewrite_rules() { add_rewrite_rule( ‘testimonials/([^/]+)(?:/([0-9]+))?/?$’, ‘index.php?category_name=testimonials&name=$matches[1]&page=$matches[2]’, ‘top’ // The rule position; either ‘top’ or ‘bottom’ (default). ); } ..with this one: add_filter( ‘category_link’, ‘custom_category_permalink’, 10, 2 ); function custom_category_permalink( $link, $cat_id ) { $slug = get_term_field( ‘slug’, $cat_id, ‘category’ ); if ( ! is_wp_error( … Read more

Alphabetical Index Page

You can do it like so: // Group the categories by their FIRST LETTER. $groups = []; foreach ( $category_list as &$term ) { $letter = strtoupper( substr( $term->name, 0, 1 ) ); if ( ! isset( $groups[ $letter ] ) ) { $groups[ $letter ] = []; } $groups[ $letter ][] = $term; } … Read more

Make parent categories not selectable

I really doubt this is filterable, so jQuery comes to rescue 🙂 The Code add_action( ‘admin_footer-post.php’, ‘wpse_22836_remove_top_categories_checkbox’ ); add_action( ‘admin_footer-post-new.php’, ‘wpse_22836_remove_top_categories_checkbox’ ); function wpse_22836_remove_top_categories_checkbox() { global $post_type; if ( ‘post’ != $post_type ) return; ?> <script type=”text/javascript”> jQuery(“#categorychecklist>li>label input”).each(function(){ jQuery(this).remove(); }); </script> <?php } The Result Advanced There’s a caveat: whenever selecting a sub-category, it … Read more

How to hide a specific category posts in my monthly archive?

There are two ways of doing it: You can use a filter to alter the query when viewing an archive page. You will need to find the ID of your category ‘blogs’ (you can obtain it from the slug using get_term_by). Alternatively you can exclude a particular category by ID. add_action( ‘pre_get_posts’, ‘my_change_query’); function my_change_query($query){ … Read more

Different templates for parent and children categories/taxonomies

I suggest creating 3 files 1) regiontemplate-country.php 2) regiontemplate-city.php These 2 will contain the templates for country & city, then 3) taxonomy-region.php In this file, add the code to load the appropriate template <?php $term = get_term_by(‘slug’, get_query_var(‘term’), ‘region’); if((int)$term->parent) get_template_part(‘regiontemplate’, ‘city’); else get_template_part(‘regiontemplate’, ‘country’);

Exclude sub category posts from category display

I rewrote the code from a post at WP Engineer: function wpse_filter_child_cats( $query ) { if ( $query->is_category ) { $queried_object = get_queried_object(); $child_cats = (array) get_term_children( $queried_object->term_id, ‘category’ ); if ( ! $query->is_admin ) //exclude the posts in child categories $query->set( ‘category__not_in’, array_merge( $child_cats ) ); } return $query; } add_filter( ‘pre_get_posts’, ‘wpse_filter_child_cats’ ); … Read more