I’ll build a full-featured 404.php template for your RX theme with SEO-safe handling, search, recent/popular sections, category/tag navigation, helpful links, and developer-friendly hooks/options.
Below is an advanced 404.php file for your RX theme. Put it here:
rx-theme/404.php
It includes: proper 404 status, SEO-safe noindex, search form, homepage link, recent posts, popular/commented posts, categories, tags, archives, random posts, sitemap links, contact link, accessibility, schema JSON-LD, hooks, and safe fallbacks.
<?php
/**
* RX Theme - Advanced 404 Template
*
* File: 404.php
*
* Purpose:
* Display a helpful, SEO-safe, user-friendly 404 error page when a visitor
* opens a URL that does not exist.
*
* Features:
* - Correct HTTP 404 status
* - SEO-safe noindex robots meta
* - Search box
* - Recent posts
* - Popular/commented posts
* - Random posts
* - Categories
* - Tags
* - Monthly archives
* - Helpful quick links
* - Optional sitemap links
* - Accessible HTML structure
* - JSON-LD WebPage schema
* - RX custom hooks
*
* @package RX_Theme
*/
defined( 'ABSPATH' ) || exit;
/**
* Make sure WordPress sends a real 404 status.
*/
status_header( 404 );
nocache_headers();
/**
* Optional:
* You may define these constants in functions.php later if you want.
*/
$rx_404_recent_posts_count = defined( 'RX_404_RECENT_POSTS_COUNT' ) ? absint( RX_404_RECENT_POSTS_COUNT ) : 6;
$rx_404_popular_posts_count = defined( 'RX_404_POPULAR_POSTS_COUNT' ) ? absint( RX_404_POPULAR_POSTS_COUNT ) : 5;
$rx_404_random_posts_count = defined( 'RX_404_RANDOM_POSTS_COUNT' ) ? absint( RX_404_RANDOM_POSTS_COUNT ) : 4;
$rx_404_categories_count = defined( 'RX_404_CATEGORIES_COUNT' ) ? absint( RX_404_CATEGORIES_COUNT ) : 12;
$rx_404_tags_count = defined( 'RX_404_TAGS_COUNT' ) ? absint( RX_404_TAGS_COUNT ) : 18;
$rx_404_archives_count = defined( 'RX_404_ARCHIVES_COUNT' ) ? absint( RX_404_ARCHIVES_COUNT ) : 12;
/**
* Current broken URL.
*/
$rx_404_current_url = home_url( add_query_arg( array(), $GLOBALS['wp']->request ?? '' ) );
$rx_404_home_url = home_url( '/' );
$rx_404_blog_name = get_bloginfo( 'name' );
$rx_404_description = get_bloginfo( 'description' );
/**
* Extract possible search keyword from requested URL.
*/
$rx_404_path = trim( wp_parse_url( $_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH ), '/' );
$rx_404_guess_keyword = '';
if ( ! empty( $rx_404_path ) ) {
$rx_404_guess_keyword = str_replace( array( '-', '_', '/', '.html', '.php' ), ' ', $rx_404_path );
$rx_404_guess_keyword = preg_replace( '/\s+/', ' ', $rx_404_guess_keyword );
$rx_404_guess_keyword = sanitize_text_field( $rx_404_guess_keyword );
}
/**
* Helper: safe SVG icon output.
*/
if ( ! function_exists( 'rx_404_icon' ) ) {
function rx_404_icon( $type = 'search' ) {
$icons = array(
'search' => '<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M21 21l-4.35-4.35m1.35-5.15a7.5 7.5 0 11-15 0 7.5 7.5 0 0115 0z" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
'home' => '<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M3 11l9-8 9 8v10a1 1 0 01-1 1h-5v-7H9v7H4a1 1 0 01-1-1V11z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
'post' => '<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M5 4h14v16H5V4zm3 4h8m-8 4h8m-8 4h5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
'tag' => '<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M20 13l-7 7L4 11V4h7l9 9z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M8 8h.01" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg>',
'folder' => '<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M3 6h7l2 2h9v10a2 2 0 01-2 2H5a2 2 0 01-2-2V6z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/></svg>',
'link' => '<svg aria-hidden="true" width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M10 13a5 5 0 007.07 0l2-2a5 5 0 00-7.07-7.07l-1.2 1.2M14 11a5 5 0 00-7.07 0l-2 2A5 5 0 0012 20.07l1.2-1.2" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',
);
return $icons[ $type ] ?? $icons['link'];
}
}
/**
* Add noindex for this 404 page.
*/
add_action(
'wp_head',
function () {
if ( is_404() ) {
echo "\n" . '<meta name="robots" content="noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1">' . "\n";
}
},
1
);
/**
* JSON-LD schema for 404 page.
*/
add_action(
'wp_head',
function () use ( $rx_404_current_url, $rx_404_blog_name ) {
if ( ! is_404() ) {
return;
}
$schema = array(
'@context' => 'https://schema.org',
'@type' => 'WebPage',
'name' => __( 'Page Not Found', 'rx-theme' ),
'description' => __( 'The requested page could not be found.', 'rx-theme' ),
'url' => esc_url_raw( $rx_404_current_url ),
'isPartOf' => array(
'@type' => 'WebSite',
'name' => $rx_404_blog_name,
'url' => home_url( '/' ),
),
);
echo "\n<script type=\"application/ld+json\">" . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . "</script>\n";
},
20
);
get_header();
do_action( 'rx_before_404_page' );
?>
<main id="primary" class="site-main rx-404-page" role="main">
<style>
.rx-404-page {
--rx-404-bg: #f8fafc;
--rx-404-card: #ffffff;
--rx-404-text: #0f172a;
--rx-404-muted: #475569;
--rx-404-border: #e2e8f0;
--rx-404-primary: #2563eb;
--rx-404-primary-dark: #1d4ed8;
--rx-404-soft: #eff6ff;
--rx-404-danger: #ef4444;
background: var(--rx-404-bg);
color: var(--rx-404-text);
padding: clamp(32px, 5vw, 80px) 16px;
}
.rx-404-wrap {
max-width: 1180px;
margin: 0 auto;
}
.rx-404-hero {
text-align: center;
background:
radial-gradient(circle at top left, rgba(37, 99, 235, 0.14), transparent 32%),
radial-gradient(circle at bottom right, rgba(239, 68, 68, 0.10), transparent 32%),
var(--rx-404-card);
border: 1px solid var(--rx-404-border);
border-radius: 28px;
padding: clamp(32px, 6vw, 72px) clamp(18px, 4vw, 48px);
box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
position: relative;
overflow: hidden;
}
.rx-404-code {
font-size: clamp(72px, 16vw, 180px);
font-weight: 900;
line-height: 0.9;
letter-spacing: -0.08em;
color: var(--rx-404-primary);
margin: 0 0 18px;
}
.rx-404-title {
font-size: clamp(28px, 5vw, 54px);
line-height: 1.08;
margin: 0 0 16px;
font-weight: 800;
}
.rx-404-description {
max-width: 760px;
margin: 0 auto 26px;
color: var(--rx-404-muted);
font-size: clamp(16px, 2vw, 19px);
line-height: 1.7;
}
.rx-404-search {
max-width: 720px;
margin: 28px auto 0;
}
.rx-404-search-form {
display: flex;
gap: 10px;
background: #fff;
border: 1px solid var(--rx-404-border);
padding: 10px;
border-radius: 18px;
box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
.rx-404-search-form label {
flex: 1;
margin: 0;
}
.rx-404-search-form input[type="search"] {
width: 100%;
min-height: 48px;
border: 0;
outline: 0;
padding: 0 14px;
font-size: 16px;
background: transparent;
color: var(--rx-404-text);
}
.rx-404-search-form button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
border: 0;
border-radius: 14px;
background: var(--rx-404-primary);
color: #fff;
padding: 0 22px;
min-height: 48px;
font-weight: 700;
cursor: pointer;
transition: transform .2s ease, background .2s ease;
}
.rx-404-search-form button:hover,
.rx-404-search-form button:focus {
background: var(--rx-404-primary-dark);
transform: translateY(-1px);
}
.rx-404-actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
justify-content: center;
margin-top: 26px;
}
.rx-404-button {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 13px 18px;
border-radius: 999px;
text-decoration: none;
font-weight: 700;
border: 1px solid var(--rx-404-border);
background: #fff;
color: var(--rx-404-text);
transition: transform .2s ease, border-color .2s ease, color .2s ease;
}
.rx-404-button:hover,
.rx-404-button:focus {
transform: translateY(-1px);
border-color: var(--rx-404-primary);
color: var(--rx-404-primary);
}
.rx-404-button-primary {
background: var(--rx-404-primary);
color: #fff;
border-color: var(--rx-404-primary);
}
.rx-404-button-primary:hover,
.rx-404-button-primary:focus {
background: var(--rx-404-primary-dark);
color: #fff;
}
.rx-404-grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 22px;
margin-top: 28px;
}
.rx-404-card {
grid-column: span 6;
background: var(--rx-404-card);
border: 1px solid var(--rx-404-border);
border-radius: 22px;
padding: 24px;
box-shadow: 0 12px 36px rgba(15, 23, 42, 0.06);
}
.rx-404-card-full {
grid-column: span 12;
}
.rx-404-card-small {
grid-column: span 4;
}
.rx-404-card-title {
display: flex;
align-items: center;
gap: 10px;
font-size: 22px;
margin: 0 0 16px;
font-weight: 800;
}
.rx-404-list {
list-style: none;
padding: 0;
margin: 0;
display: grid;
gap: 12px;
}
.rx-404-list li {
border-bottom: 1px dashed var(--rx-404-border);
padding-bottom: 12px;
}
.rx-404-list li:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.rx-404-list a {
color: var(--rx-404-text);
text-decoration: none;
font-weight: 700;
}
.rx-404-list a:hover,
.rx-404-list a:focus {
color: var(--rx-404-primary);
text-decoration: underline;
}
.rx-404-meta {
display: block;
margin-top: 4px;
color: var(--rx-404-muted);
font-size: 14px;
}
.rx-404-pill-list {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 0;
margin: 0;
list-style: none;
}
.rx-404-pill-list a {
display: inline-flex;
align-items: center;
padding: 9px 13px;
background: var(--rx-404-soft);
border: 1px solid #dbeafe;
border-radius: 999px;
color: var(--rx-404-primary-dark);
text-decoration: none;
font-weight: 700;
font-size: 14px;
}
.rx-404-pill-list a:hover,
.rx-404-pill-list a:focus {
background: var(--rx-404-primary);
color: #fff;
}
.rx-404-help {
background: #fff7ed;
border-color: #fed7aa;
}
.rx-404-debug {
margin-top: 28px;
padding: 16px;
border-radius: 16px;
background: #0f172a;
color: #e2e8f0;
font-size: 13px;
overflow: auto;
}
.rx-404-debug code {
color: #bfdbfe;
}
.screen-reader-text {
position: absolute !important;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 900px) {
.rx-404-card,
.rx-404-card-small {
grid-column: span 12;
}
}
@media (max-width: 640px) {
.rx-404-search-form {
flex-direction: column;
}
.rx-404-search-form button {
width: 100%;
}
.rx-404-card {
padding: 18px;
}
}
</style>
<div class="rx-404-wrap">
<section class="rx-404-hero" aria-labelledby="rx-404-title">
<p class="rx-404-code" aria-hidden="true">404</p>
<h1 id="rx-404-title" class="rx-404-title">
<?php esc_html_e( 'Oops! This page could not be found.', 'rx-theme' ); ?>
</h1>
<p class="rx-404-description">
<?php
printf(
esc_html__(
'The page you are looking for may have been moved, deleted, renamed, or the URL may be incorrect. You can search %1$s or return to the homepage.',
'rx-theme'
),
esc_html( $rx_404_blog_name )
);
?>
</p>
<div class="rx-404-search" role="search">
<form role="search" method="get" class="rx-404-search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label>
<span class="screen-reader-text"><?php esc_html_e( 'Search for:', 'rx-theme' ); ?></span>
<input
type="search"
name="s"
value="<?php echo esc_attr( $rx_404_guess_keyword ); ?>"
placeholder="<?php esc_attr_e( 'Search articles, guides, topics...', 'rx-theme' ); ?>"
autocomplete="off"
/>
</label>
<button type="submit">
<?php echo rx_404_icon( 'search' ); ?>
<span><?php esc_html_e( 'Search', 'rx-theme' ); ?></span>
</button>
</form>
</div>
<div class="rx-404-actions">
<a class="rx-404-button rx-404-button-primary" href="<?php echo esc_url( $rx_404_home_url ); ?>">
<?php echo rx_404_icon( 'home' ); ?>
<span><?php esc_html_e( 'Go to Homepage', 'rx-theme' ); ?></span>
</a>
<?php if ( get_option( 'page_for_posts' ) ) : ?>
<a class="rx-404-button" href="<?php echo esc_url( get_permalink( get_option( 'page_for_posts' ) ) ); ?>">
<?php echo rx_404_icon( 'post' ); ?>
<span><?php esc_html_e( 'Visit Blog', 'rx-theme' ); ?></span>
</a>
<?php endif; ?>
<?php
$rx_contact_page = get_page_by_path( 'contact' );
if ( $rx_contact_page ) :
?>
<a class="rx-404-button" href="<?php echo esc_url( get_permalink( $rx_contact_page ) ); ?>">
<?php echo rx_404_icon( 'link' ); ?>
<span><?php esc_html_e( 'Contact Us', 'rx-theme' ); ?></span>
</a>
<?php endif; ?>
</div>
</section>
<?php do_action( 'rx_404_after_hero' ); ?>
<section class="rx-404-grid" aria-label="<?php esc_attr_e( 'Helpful content', 'rx-theme' ); ?>">
<?php
/**
* Recent posts.
*/
$rx_recent_posts = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $rx_404_recent_posts_count,
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
?>
<?php if ( $rx_recent_posts->have_posts() ) : ?>
<div class="rx-404-card">
<h2 class="rx-404-card-title">
<?php echo rx_404_icon( 'post' ); ?>
<span><?php esc_html_e( 'Latest Articles', 'rx-theme' ); ?></span>
</h2>
<ul class="rx-404-list">
<?php
while ( $rx_recent_posts->have_posts() ) :
$rx_recent_posts->the_post();
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
<span class="rx-404-meta">
<?php echo esc_html( get_the_date() ); ?>
<?php
$category_list = get_the_category_list( ', ' );
if ( $category_list ) {
echo ' · ';
echo wp_kses_post( $category_list );
}
?>
</span>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php
/**
* Popular posts by comment count.
*/
$rx_popular_posts = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $rx_404_popular_posts_count,
'orderby' => 'comment_count',
'order' => 'DESC',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
?>
<?php if ( $rx_popular_posts->have_posts() ) : ?>
<div class="rx-404-card">
<h2 class="rx-404-card-title">
<?php echo rx_404_icon( 'post' ); ?>
<span><?php esc_html_e( 'Popular Articles', 'rx-theme' ); ?></span>
</h2>
<ul class="rx-404-list">
<?php
while ( $rx_popular_posts->have_posts() ) :
$rx_popular_posts->the_post();
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
<span class="rx-404-meta">
<?php
printf(
esc_html(
_n(
'%s comment',
'%s comments',
get_comments_number(),
'rx-theme'
)
),
esc_html( number_format_i18n( get_comments_number() ) )
);
?>
</span>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php
/**
* Random useful posts.
*/
$rx_random_posts = new WP_Query(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $rx_404_random_posts_count,
'orderby' => 'rand',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
)
);
?>
<?php if ( $rx_random_posts->have_posts() ) : ?>
<div class="rx-404-card rx-404-card-small">
<h2 class="rx-404-card-title">
<?php echo rx_404_icon( 'link' ); ?>
<span><?php esc_html_e( 'Try These', 'rx-theme' ); ?></span>
</h2>
<ul class="rx-404-list">
<?php
while ( $rx_random_posts->have_posts() ) :
$rx_random_posts->the_post();
?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php
/**
* Categories.
*/
$rx_categories = get_categories(
array(
'orderby' => 'count',
'order' => 'DESC',
'number' => $rx_404_categories_count,
'hide_empty' => true,
)
);
?>
<?php if ( ! empty( $rx_categories ) && ! is_wp_error( $rx_categories ) ) : ?>
<div class="rx-404-card rx-404-card-small">
<h2 class="rx-404-card-title">
<?php echo rx_404_icon( 'folder' ); ?>
<span><?php esc_html_e( 'Browse Categories', 'rx-theme' ); ?></span>
</h2>
<ul class="rx-404-pill-list">
<?php foreach ( $rx_categories as $rx_category ) : ?>
<li>
<a href="<?php echo esc_url( get_category_link( $rx_category->term_id ) ); ?>">
<?php echo esc_html( $rx_category->name ); ?>
<?php echo esc_html( ' (' . number_format_i18n( $rx_category->count ) . ')' ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php
/**
* Tags.
*/
$rx_tags = get_tags(
array(
'orderby' => 'count',
'order' => 'DESC',
'number' => $rx_404_tags_count,
'hide_empty' => true,
)
);
?>
<?php if ( ! empty( $rx_tags ) && ! is_wp_error( $rx_tags ) ) : ?>
<div class="rx-404-card rx-404-card-small">
<h2 class="rx-404-card-title">
<?php echo rx_404_icon( 'tag' ); ?>
<span><?php esc_html_e( 'Popular Tags', 'rx-theme' ); ?></span>
</h2>
<ul class="rx-404-pill-list">
<?php foreach ( $rx_tags as $rx_tag ) : ?>
<li>
<a href="<?php echo esc_url( get_tag_link( $rx_tag->term_id ) ); ?>">
<?php echo esc_html( $rx_tag->name ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<?php
/**
* Monthly archives.
*/
ob_start();
wp_get_archives(
array(
'type' => 'monthly',
'limit' => $rx_404_archives_count,
'format' => 'custom',
'before' => '<li>',
'after' => '</li>',
'show_post_count' => true,
)
);
$rx_archives_html = ob_get_clean();
?>
<?php if ( ! empty( $rx_archives_html ) ) : ?>
<div class="rx-404-card">
<h2 class="rx-404-card-title">
<?php echo rx_404_icon( 'folder' ); ?>
<span><?php esc_html_e( 'Monthly Archives', 'rx-theme' ); ?></span>
</h2>
<ul class="rx-404-list">
<?php echo wp_kses_post( $rx_archives_html ); ?>
</ul>
</div>
<?php endif; ?>
<?php
/**
* Helpful static links.
*/
$rx_helpful_links = array(
array(
'label' => __( 'Homepage', 'rx-theme' ),
'url' => home_url( '/' ),
),
array(
'label' => __( 'All Posts', 'rx-theme' ),
'url' => get_option( 'page_for_posts' ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' ),
),
);
$rx_about_page = get_page_by_path( 'about' );
if ( $rx_about_page ) {
$rx_helpful_links[] = array(
'label' => __( 'About', 'rx-theme' ),
'url' => get_permalink( $rx_about_page ),
);
}
$rx_contact_page = get_page_by_path( 'contact' );
if ( $rx_contact_page ) {
$rx_helpful_links[] = array(
'label' => __( 'Contact', 'rx-theme' ),
'url' => get_permalink( $rx_contact_page ),
);
}
$rx_privacy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
if ( $rx_privacy_page_id ) {
$rx_helpful_links[] = array(
'label' => __( 'Privacy Policy', 'rx-theme' ),
'url' => get_permalink( $rx_privacy_page_id ),
);
}
/**
* Sitemap guesses.
*/
$rx_sitemap_candidates = array(
'sitemap.xml',
'sitemap_index.xml',
'wp-sitemap.xml',
);
foreach ( $rx_sitemap_candidates as $rx_sitemap_candidate ) {
$rx_helpful_links[] = array(
'label' => sprintf(
/* translators: %s: sitemap file name */
__( 'Sitemap: %s', 'rx-theme' ),
$rx_sitemap_candidate
),
'url' => home_url( '/' . $rx_sitemap_candidate ),
);
}
?>
<div class="rx-404-card rx-404-card-full rx-404-help">
<h2 class="rx-404-card-title">
<?php echo rx_404_icon( 'link' ); ?>
<span><?php esc_html_e( 'Helpful Links', 'rx-theme' ); ?></span>
</h2>
<ul class="rx-404-pill-list">
<?php foreach ( $rx_helpful_links as $rx_helpful_link ) : ?>
<li>
<a href="<?php echo esc_url( $rx_helpful_link['url'] ); ?>">
<?php echo esc_html( $rx_helpful_link['label'] ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
</section>
<?php
/**
* Optional widget area.
*
* Add this in functions.php if you want:
*
* register_sidebar( array(
* 'name' => __( '404 Page Widgets', 'rx-theme' ),
* 'id' => 'rx-404-widgets',
* 'description' => __( 'Widgets shown on the 404 page.', 'rx-theme' ),
* 'before_widget' => '<section class="widget rx-404-widget">',
* 'after_widget' => '</section>',
* 'before_title' => '<h2 class="widget-title">',
* 'after_title' => '</h2>',
* ) );
*/
if ( is_active_sidebar( 'rx-404-widgets' ) ) :
?>
<section class="rx-404-card rx-404-card-full" aria-label="<?php esc_attr_e( 'More help', 'rx-theme' ); ?>">
<?php dynamic_sidebar( 'rx-404-widgets' ); ?>
</section>
<?php endif; ?>
<?php if ( current_user_can( 'manage_options' ) && defined( 'WP_DEBUG' ) && WP_DEBUG ) : ?>
<div class="rx-404-debug" aria-label="<?php esc_attr_e( 'Debug information', 'rx-theme' ); ?>">
<strong><?php esc_html_e( 'Admin Debug Info:', 'rx-theme' ); ?></strong><br>
<?php esc_html_e( 'Requested URL:', 'rx-theme' ); ?>
<code><?php echo esc_html( $rx_404_current_url ); ?></code><br>
<?php esc_html_e( 'Suggested search keyword:', 'rx-theme' ); ?>
<code><?php echo esc_html( $rx_404_guess_keyword ); ?></code>
</div>
<?php endif; ?>
</div>
</main>
<?php
do_action( 'rx_after_404_page' );
get_footer();
For extra widget support, add this to your theme functions.php:
/**
* RX Theme - 404 Page Widget Area
*/
function rx_register_404_widget_area() {
register_sidebar(
array(
'name' => __( '404 Page Widgets', 'rx-theme' ),
'id' => 'rx-404-widgets',
'description' => __( 'Widgets shown on the 404 error page.', 'rx-theme' ),
'before_widget' => '<section id="%1$s" class="widget rx-404-widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'rx_register_404_widget_area' );
And optional constants for easy control:
/**
* RX 404 Template Controls
*/
define( 'RX_404_RECENT_POSTS_COUNT', 6 );
define( 'RX_404_POPULAR_POSTS_COUNT', 5 );
define( 'RX_404_RANDOM_POSTS_COUNT', 4 );
define( 'RX_404_CATEGORIES_COUNT', 12 );
define( 'RX_404_TAGS_COUNT', 18 );
define( 'RX_404_ARCHIVES_COUNT', 12 );