Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-5-haiku-20241022· AnthropicHugging Face LMArena Human Preference 140K

how to use deffernet 404 page for defferent slug in wordpress

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-7-sonnet-20250219’s answer.
  1. User

    how to use deffernet 404 page for defferent slug in wordpress

  2. Claude Assistant

    Here's a comprehensive guide to creating different 404 error pages for different slugs/sections in WordPress:

    1. Method 1: Using Template Hierarchy
    // In your theme's directory, create specific 404 templates
    404.php (default catch-all)
    404-products.php (for product section)
    404-blog.php (for blog section)
    
    1. Method 2: Custom Function in functions.php
    function custom_404_page() {
        global $wp_query;
        
        // Check current section/post type
        if (is_product()) {
            include(get_template_directory() . '/404-products.php');
            exit;
        }
        
        if (is_blog()) {
            include(get_template_directory() . '/404-blog.php');
            exit;
        }
        
        // Default 404 page
        include(get_template_directory() . '/404.php');
        exit;
    }
    add_action('template_redirect', 'custom_404_page');
    
    1. Method 3: Plugin-Based Solution
    • Use plugins like "Custom 404 Pro" or "404page"
    • These allow creating multiple 404 pages mapped to different sections
    1. Advanced Method: Conditional Redirects
    function section_specific_404_redirect() {
        if (is_404()) {
            $current_url = $_SERVER['REQUEST_URI'];
            
            if (strpos($current_url, '/products/') !== false) {
                wp_redirect(home_url('/custom-product-404'));
                exit;
            }
            
            if (strpos($current_url, '/blog/') !== false) {
                wp_redirect(home_url('/custom-blog-404'));
                exit;
            }
        }
    }
    add_action('template_redirect', 'section_specific_404_redirect');
    

    Key Considerations:

    • Always test thoroughly
    • Ensure proper error handling
    • Consider user experience
    • Maintain consistent design across 404 pages

    Recommended Best Practices:

    • Include search functionality
    • Provide navigation links
    • Keep design consistent with site theme
    • Offer helpful suggestions/alternatives

    Would you like me to elaborate on any of these methods?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.