Page navigation within a category

For this particular problem you need to change this.. <?php if ( $wp_query->max_num_pages > 1 ) : ?> For.. <?php if ( $my_query->max_num_pages > 1 ) : ?> However, like Rarst said, if you’re looking to change the “main” query, then query_posts is really what you’re looking for, and the change above wouldn’t be required … Read more

Redirecting category link to first child post

You are much too late in the page load sequence to redirect. You need to redirect before headers are sent to the browser. The template_redirect hook should be a pretty good option: function redirect_cat_wpse_207298() { if (is_category()) { global $post; wp_safe_redirect(get_permalink($post->ID)); die; } } add_action(‘template_redirect’,’redirect_cat_wpse_207298′);

How to add HTML5 ‘required’ attribute to wp_dropdown_categories() without JavaScripts?

If you want to apply the required attribute every time you use wp_categories_dropdown, use wp_dropdown_cats filter as suggested in other answers: add_filter( ‘wp_dropdown_cats’, ‘wp_dropdown_categories_required’ ); function wp_dropdown_categories_required( $output ){ return preg_replace( ‘^’ . preg_quote( ‘<select ‘ ) . ‘^’, ‘<select required ‘, $output ); } If you want to apply the required attribute only in … Read more

Is there a function to cause empty categories not to show in menus?

add_filter( ‘wp_get_nav_menu_items’, ‘nav_remove_empty_category_menu_item’, 10, 3 ); function nav_remove_empty_category_menu_item ( $items, $menu, $args ) { global $wpdb; $nopost = $wpdb->get_col( “SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE count = 0” ); foreach ( $items as $key => $item ) { if ( ( ‘taxonomy’ == $item->type ) && ( in_array( $item->object_id, $nopost ) ) ) { unset( $items[$key] … Read more

Exclude a category from the filed under list only on some templates

You can add conditional statements before applying the logic to modify the categories. For example, I added a check that will bail and return the unmodified list of categories if we’re not on the category archive page: // Add the filter to ‘the_category’ tag. add_filter( ‘the_category’, ‘the_category_filter’, 10, 2 ); function the_category_filter( $thelist, $separator=” ” … Read more