how to use deffernet 404 page for defferent slug in wordpress
- User
how to use deffernet 404 page for defferent slug in wordpress
Assistant
For WordPress, you can create different 404 pages for different URL slugs by using a custom 404.php template with conditional logic. Here's how:
- Create a custom 404.php file in your theme directory
- Add conditional statements to check the current URL path
- Display different content based on the slug
<?php get_header(); ?> <div class="error-page-container"> <?php // Get the current URL path $current_url = $_SERVER['REQUEST_URI']; // Check for specific slugs and display custom content if (strpos($current_url, '/products/') !== false) { // Product-specific 404 page ?> <h1>Product Not Found</h1> <p>Sorry, the product you're looking for doesn't exist. Browse our <a href="/products/">product catalog</a> instead.</p> <?php } elseif (strpos($current_url, '/blog/') !== false) { // Blog-specific 404 page ?> <h1>Blog Post Not Found</h1> <p>The blog post you're looking for has been moved or deleted. Check out our <a href="/blog/">latest articles</a>.</p> <?php } else { // Default 404 page ?> <h1>Page Not Found</h1> <p>Sorry, the page you requested could not be found. Please check the URL or return to our <a href="<?php echo home_url(); ?>">homepage</a>.</p> <?php } ?> </div> <?php get_footer(); ?>Would you like me to explain or break down this code?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.