// 1. Fix category pagination rewrite rules add_filter('rewrite_rules_array', function($rules) { $new_rules = array(); // Get all categories $categories = get_categories(array('hide_empty' => false)); foreach($categories as $category) { // Fix numeric category pagination if (is_numeric($category->slug)) { $new_rules['category/' . $category->term_id . '/page/([0-9]+)/?$'] = 'index.php?cat=' . $category->term_id . '&paged=$matches[1]'; } // Fix slug-based category pagination $new_rules['category/' . $category->slug . '/page/([0-9]+)/?$'] = 'index.php?category_name=' . $category->slug . '&paged=$matches[1]'; } return array_merge($new_rules, $rules); }, 10, 1); // 2. Add related posts to single posts add_filter('the_content', function($content) { if (!is_single() || !is_main_query()) return $content; global $post; $categories = wp_get_post_categories($post->ID); if (empty($categories)) return $content; $related_posts = get_posts(array( 'category__in' => $categories, 'numberposts' => 5, 'post__not_in' => array($post->ID), 'orderby' => 'rand' )); if ($related_posts) { $related_html = '
'; $content .= $related_html; } return $content; }, 10, 1); // 3. Add pagination meta tags for SEO add_action('wp_head', function() { global $wp_query, $paged; if (!is_paged()) return; $max_pages = $wp_query->max_num_pages; $current_page = max(1, get_query_var('paged', 1)); // Add canonical for first page if (is_category() || is_archive()) { echo '' . "\n"; } // Add prev/next links if ($current_page > 1) { echo '' . "\n"; } if ($current_page < $max_pages) { echo '' . "\n"; } // Noindex deep pages (page 4+) if ($current_page > 3) { echo '' . "\n"; } }, 1); // 4. Create category hub shortcode add_shortcode('category_hub', function() { $categories = get_categories(array( 'hide_empty' => false, 'orderby' => 'count', 'order' => 'DESC' )); if (empty($categories)) return ''; $output = '%d articles