// 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 = '
'; $output .= '

Toutes nos catégories

'; $output .= '
'; foreach($categories as $cat) { $count = $cat->count; $output .= sprintf( '

%s

%d articles

', get_category_link($cat->term_id), $cat->name, $count ); } $output .= '
'; return $output; }); // 5. Add breadcrumbs add_action('generate_before_main_content', function() { if (is_home() || is_front_page()) return; echo ''; }, 5); // 6. Archive pages widget for sidebar add_action('widgets_init', function() { register_sidebar(array( 'name' => 'Archive Sidebar', 'id' => 'archive-sidebar', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' )); }); // 7. Ensure blog page exists add_action('init', function() { $blog_page = get_page_by_path('blog'); if (!$blog_page) { $blog_id = wp_insert_post(array( 'post_title' => 'Blog - Tous nos articles', 'post_content' => '[category_hub]', 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'blog', 'post_author' => 1 )); if ($blog_id) { update_option('page_for_posts', $blog_id); } } }, 20); // 8. Fix pagination for numeric categories add_action('pre_get_posts', function($query) { if (!$query->is_main_query() || is_admin()) return; if ($query->is_category()) { $cat_id = $query->get('cat'); if ($cat_id) { $paged = get_query_var('paged') ? get_query_var('paged') : 1; $query->set('paged', $paged); } } }, 10, 1); https://point-fort-fichet-paris.com/post-sitemap.xml 2024-09-08T18:44:59+00:00 https://point-fort-fichet-paris.com/post-sitemap2.xml 2024-09-08T18:44:59+00:00 https://point-fort-fichet-paris.com/page-sitemap.xml 2025-09-21T00:02:29+00:00 https://point-fort-fichet-paris.com/category-sitemap.xml 2024-09-08T18:44:59+00:00 https://point-fort-fichet-paris.com/gblocks_pattern_collections-sitemap.xml 2024-09-05T16:52:33+00:00 https://point-fort-fichet-paris.com/author-sitemap.xml 2025-09-20T19:13:45+00:00