I’ll build this as a full WordPress theme footer menu template part: safe checks, multiple footer menu columns, fallbacks, social links, legal links, schema-friendly markup, accessibility, hooks, filters, and customization-ready code.
Below is an advanced template-parts/footer/footer-menu.php file for your Rx Theme.
Create this file:
rx-theme/template-parts/footer/footer-menu.php
Then paste this full code:
<?php
/**
* Template Part: Advanced Footer Menu
*
* File: template-parts/footer/footer-menu.php
*
* Features:
* - Multiple footer menu locations
* - Automatic fallback links
* - Footer quick links
* - Footer legal links
* - Footer social links
* - Footer contact links
* - Dynamic copyright
* - Back to top link
* - Accessibility-friendly markup
* - SEO-friendly internal links
* - Schema.org support
* - Customizer/filter friendly
* - Safe escaping and sanitization
*
* @package Rx_Theme
*/
defined( 'ABSPATH' ) || exit;
/**
* ------------------------------------------------------------
* Helper: Check menu location safely
* ------------------------------------------------------------
*/
if ( ! function_exists( 'rx_theme_has_menu_location' ) ) {
function rx_theme_has_menu_location( $location ) {
return has_nav_menu( $location );
}
}
/**
* ------------------------------------------------------------
* Helper: Render WordPress nav menu safely
* ------------------------------------------------------------
*/
if ( ! function_exists( 'rx_theme_render_footer_nav_menu' ) ) {
function rx_theme_render_footer_nav_menu( $args = array() ) {
$defaults = array(
'theme_location' => '',
'menu_class' => 'rx-footer-menu__list',
'container' => false,
'depth' => 2,
'fallback_cb' => false,
'link_before' => '<span>',
'link_after' => '</span>',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'echo' => true,
);
$args = wp_parse_args( $args, $defaults );
if ( empty( $args['theme_location'] ) || ! has_nav_menu( $args['theme_location'] ) ) {
return;
}
wp_nav_menu( $args );
}
}
/**
* ------------------------------------------------------------
* Helper: Fallback footer links
* ------------------------------------------------------------
*/
if ( ! function_exists( 'rx_theme_footer_fallback_links' ) ) {
function rx_theme_footer_fallback_links() {
$links = array(
array(
'label' => __( 'Home', 'rx-theme' ),
'url' => home_url( '/' ),
),
array(
'label' => __( 'Blog', 'rx-theme' ),
'url' => get_post_type_archive_link( 'post' ) ? get_post_type_archive_link( 'post' ) : home_url( '/' ),
),
array(
'label' => __( 'About', 'rx-theme' ),
'url' => home_url( '/about/' ),
),
array(
'label' => __( 'Contact', 'rx-theme' ),
'url' => home_url( '/contact/' ),
),
array(
'label' => __( 'Privacy Policy', 'rx-theme' ),
'url' => get_privacy_policy_url() ? get_privacy_policy_url() : home_url( '/privacy-policy/' ),
),
);
$links = apply_filters( 'rx_theme_footer_fallback_links', $links );
if ( empty( $links ) || ! is_array( $links ) ) {
return;
}
?>
<ul class="rx-footer-menu__list rx-footer-menu__list--fallback">
<?php foreach ( $links as $link ) : ?>
<?php
$label = isset( $link['label'] ) ? $link['label'] : '';
$url = isset( $link['url'] ) ? $link['url'] : '';
if ( empty( $label ) || empty( $url ) ) {
continue;
}
?>
<li class="rx-footer-menu__item">
<a class="rx-footer-menu__link" href="<?php echo esc_url( $url ); ?>">
<span><?php echo esc_html( $label ); ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php
}
}
/**
* ------------------------------------------------------------
* Helper: Footer social links
* ------------------------------------------------------------
*/
if ( ! function_exists( 'rx_theme_footer_social_links' ) ) {
function rx_theme_footer_social_links() {
/**
* You can edit these URLs directly or filter them from functions.php.
*/
$social_links = array(
'facebook' => array(
'label' => __( 'Facebook', 'rx-theme' ),
'url' => '',
'icon' => 'facebook',
),
'x' => array(
'label' => __( 'X / Twitter', 'rx-theme' ),
'url' => '',
'icon' => 'x',
),
'linkedin' => array(
'label' => __( 'LinkedIn', 'rx-theme' ),
'url' => '',
'icon' => 'linkedin',
),
'youtube' => array(
'label' => __( 'YouTube', 'rx-theme' ),
'url' => '',
'icon' => 'youtube',
),
'github' => array(
'label' => __( 'GitHub', 'rx-theme' ),
'url' => '',
'icon' => 'github',
),
);
$social_links = apply_filters( 'rx_theme_footer_social_links', $social_links );
$has_social = false;
foreach ( $social_links as $social ) {
if ( ! empty( $social['url'] ) ) {
$has_social = true;
break;
}
}
if ( ! $has_social ) {
return;
}
?>
<nav class="rx-footer-social" aria-label="<?php esc_attr_e( 'Footer social links', 'rx-theme' ); ?>">
<ul class="rx-footer-social__list">
<?php foreach ( $social_links as $key => $social ) : ?>
<?php
$label = isset( $social['label'] ) ? $social['label'] : ucfirst( $key );
$url = isset( $social['url'] ) ? $social['url'] : '';
$icon = isset( $social['icon'] ) ? $social['icon'] : $key;
if ( empty( $url ) ) {
continue;
}
?>
<li class="rx-footer-social__item rx-footer-social__item--<?php echo esc_attr( sanitize_html_class( $key ) ); ?>">
<a
class="rx-footer-social__link"
href="<?php echo esc_url( $url ); ?>"
target="_blank"
rel="noopener noreferrer me"
aria-label="<?php echo esc_attr( $label ); ?>"
>
<span class="rx-footer-social__icon rx-footer-social__icon--<?php echo esc_attr( sanitize_html_class( $icon ) ); ?>" aria-hidden="true"></span>
<span class="screen-reader-text"><?php echo esc_html( $label ); ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
</nav>
<?php
}
}
/**
* ------------------------------------------------------------
* Helper: Footer legal links
* ------------------------------------------------------------
*/
if ( ! function_exists( 'rx_theme_footer_legal_links' ) ) {
function rx_theme_footer_legal_links() {
$legal_links = array();
if ( get_privacy_policy_url() ) {
$legal_links[] = array(
'label' => __( 'Privacy Policy', 'rx-theme' ),
'url' => get_privacy_policy_url(),
);
}
$legal_links[] = array(
'label' => __( 'Terms & Conditions', 'rx-theme' ),
'url' => home_url( '/terms-and-conditions/' ),
);
$legal_links[] = array(
'label' => __( 'Disclaimer', 'rx-theme' ),
'url' => home_url( '/disclaimer/' ),
);
$legal_links[] = array(
'label' => __( 'Contact', 'rx-theme' ),
'url' => home_url( '/contact/' ),
);
$legal_links = apply_filters( 'rx_theme_footer_legal_links', $legal_links );
if ( empty( $legal_links ) || ! is_array( $legal_links ) ) {
return;
}
?>
<nav class="rx-footer-legal" aria-label="<?php esc_attr_e( 'Footer legal links', 'rx-theme' ); ?>">
<ul class="rx-footer-legal__list">
<?php foreach ( $legal_links as $link ) : ?>
<?php
$label = isset( $link['label'] ) ? $link['label'] : '';
$url = isset( $link['url'] ) ? $link['url'] : '';
if ( empty( $label ) || empty( $url ) ) {
continue;
}
?>
<li class="rx-footer-legal__item">
<a class="rx-footer-legal__link" href="<?php echo esc_url( $url ); ?>">
<?php echo esc_html( $label ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</nav>
<?php
}
}
/**
* ------------------------------------------------------------
* Helper: Footer contact information
* ------------------------------------------------------------
*/
if ( ! function_exists( 'rx_theme_footer_contact_info' ) ) {
function rx_theme_footer_contact_info() {
$contact_items = array(
'email' => array(
'label' => __( 'Email', 'rx-theme' ),
'value' => get_option( 'admin_email' ),
'url' => 'mailto:' . antispambot( get_option( 'admin_email' ) ),
),
'contact' => array(
'label' => __( 'Contact Page', 'rx-theme' ),
'value' => __( 'Contact us', 'rx-theme' ),
'url' => home_url( '/contact/' ),
),
);
$contact_items = apply_filters( 'rx_theme_footer_contact_items', $contact_items );
if ( empty( $contact_items ) || ! is_array( $contact_items ) ) {
return;
}
?>
<ul class="rx-footer-contact__list">
<?php foreach ( $contact_items as $key => $item ) : ?>
<?php
$label = isset( $item['label'] ) ? $item['label'] : '';
$value = isset( $item['value'] ) ? $item['value'] : '';
$url = isset( $item['url'] ) ? $item['url'] : '';
if ( empty( $label ) || empty( $value ) ) {
continue;
}
?>
<li class="rx-footer-contact__item rx-footer-contact__item--<?php echo esc_attr( sanitize_html_class( $key ) ); ?>">
<span class="rx-footer-contact__label">
<?php echo esc_html( $label ); ?>:
</span>
<?php if ( ! empty( $url ) ) : ?>
<a class="rx-footer-contact__link" href="<?php echo esc_url( $url ); ?>">
<?php echo esc_html( antispambot( $value ) ); ?>
</a>
<?php else : ?>
<span class="rx-footer-contact__value">
<?php echo esc_html( $value ); ?>
</span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php
}
}
/**
* ------------------------------------------------------------
* Data
* ------------------------------------------------------------
*/
$site_name = get_bloginfo( 'name' );
$site_description = get_bloginfo( 'description' );
$current_year = gmdate( 'Y' );
$footer_columns = array(
array(
'id' => 'footer-menu-1',
'title' => __( 'Explore', 'rx-theme' ),
'menu_location' => 'footer_menu_1',
),
array(
'id' => 'footer-menu-2',
'title' => __( 'Resources', 'rx-theme' ),
'menu_location' => 'footer_menu_2',
),
array(
'id' => 'footer-menu-3',
'title' => __( 'Company', 'rx-theme' ),
'menu_location' => 'footer_menu_3',
),
array(
'id' => 'footer-menu-4',
'title' => __( 'Support', 'rx-theme' ),
'menu_location' => 'footer_menu_4',
),
);
$footer_columns = apply_filters( 'rx_theme_footer_menu_columns', $footer_columns );
?>
<section
id="rx-footer-menu"
class="rx-footer-menu"
aria-labelledby="rx-footer-menu-title"
itemscope
itemtype="https://schema.org/WPFooter"
>
<h2 id="rx-footer-menu-title" class="screen-reader-text">
<?php esc_html_e( 'Footer navigation', 'rx-theme' ); ?>
</h2>
<div class="rx-footer-menu__inner">
<?php do_action( 'rx_theme_before_footer_menu' ); ?>
<div class="rx-footer-menu__top">
<div class="rx-footer-menu__brand" itemprop="publisher" itemscope itemtype="https://schema.org/Organization">
<?php if ( has_custom_logo() ) : ?>
<div class="rx-footer-menu__logo" itemprop="logo">
<?php the_custom_logo(); ?>
</div>
<?php else : ?>
<p class="rx-footer-menu__site-title" itemprop="name">
<a class="rx-footer-menu__site-link" href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php echo esc_html( $site_name ); ?>
</a>
</p>
<?php endif; ?>
<?php if ( ! empty( $site_description ) ) : ?>
<p class="rx-footer-menu__description" itemprop="description">
<?php echo esc_html( $site_description ); ?>
</p>
<?php endif; ?>
<?php rx_theme_footer_social_links(); ?>
</div>
<?php if ( ! empty( $footer_columns ) && is_array( $footer_columns ) ) : ?>
<div class="rx-footer-menu__columns">
<?php foreach ( $footer_columns as $column ) : ?>
<?php
$column_id = isset( $column['id'] ) ? sanitize_html_class( $column['id'] ) : '';
$column_title = isset( $column['title'] ) ? $column['title'] : '';
$menu_location = isset( $column['menu_location'] ) ? $column['menu_location'] : '';
if ( empty( $column_id ) ) {
$column_id = 'rx-footer-column-' . wp_rand( 100, 999 );
}
$title_id = $column_id . '-title';
?>
<div class="rx-footer-menu__column rx-footer-menu__column--<?php echo esc_attr( $column_id ); ?>">
<?php if ( ! empty( $column_title ) ) : ?>
<h3 id="<?php echo esc_attr( $title_id ); ?>" class="rx-footer-menu__heading">
<?php echo esc_html( $column_title ); ?>
</h3>
<?php endif; ?>
<nav
class="rx-footer-menu__nav"
aria-labelledby="<?php echo esc_attr( $title_id ); ?>"
>
<?php
if ( ! empty( $menu_location ) && has_nav_menu( $menu_location ) ) {
rx_theme_render_footer_nav_menu(
array(
'theme_location' => $menu_location,
'menu_class' => 'rx-footer-menu__list rx-footer-menu__list--' . sanitize_html_class( $menu_location ),
'depth' => 2,
)
);
} else {
rx_theme_footer_fallback_links();
}
?>
</nav>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="rx-footer-menu__contact">
<h3 class="rx-footer-menu__heading">
<?php esc_html_e( 'Contact', 'rx-theme' ); ?>
</h3>
<?php rx_theme_footer_contact_info(); ?>
</div>
</div>
<div class="rx-footer-menu__middle">
<?php if ( is_active_sidebar( 'footer-widgets' ) ) : ?>
<div class="rx-footer-menu__widgets">
<?php dynamic_sidebar( 'footer-widgets' ); ?>
</div>
<?php endif; ?>
</div>
<div class="rx-footer-menu__bottom">
<div class="rx-footer-menu__copyright">
<p>
© <?php echo esc_html( $current_year ); ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php echo esc_html( $site_name ); ?>
</a>.
<?php esc_html_e( 'All rights reserved.', 'rx-theme' ); ?>
</p>
</div>
<?php rx_theme_footer_legal_links(); ?>
<a class="rx-footer-menu__back-to-top" href="#page" aria-label="<?php esc_attr_e( 'Back to top', 'rx-theme' ); ?>">
<span aria-hidden="true">↑</span>
<span class="screen-reader-text"><?php esc_html_e( 'Back to top', 'rx-theme' ); ?></span>
</a>
</div>
<?php do_action( 'rx_theme_after_footer_menu' ); ?>
</div>
</section>
Also add these menu locations in your inc/core/menus.php or inside functions.php:
<?php
/**
* Register Rx Theme Menus
*/
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'rx_theme_register_menus' ) ) {
function rx_theme_register_menus() {
register_nav_menus(
array(
'primary_menu' => esc_html__( 'Primary Menu', 'rx-theme' ),
'footer_menu_1' => esc_html__( 'Footer Menu 1 - Explore', 'rx-theme' ),
'footer_menu_2' => esc_html__( 'Footer Menu 2 - Resources', 'rx-theme' ),
'footer_menu_3' => esc_html__( 'Footer Menu 3 - Company', 'rx-theme' ),
'footer_menu_4' => esc_html__( 'Footer Menu 4 - Support', 'rx-theme' ),
)
);
}
}
add_action( 'after_setup_theme', 'rx_theme_register_menus' );
Also register the footer widget area:
<?php
/**
* Register Rx Theme Footer Widget Area
*/
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'rx_theme_register_footer_widgets' ) ) {
function rx_theme_register_footer_widgets() {
register_sidebar(
array(
'name' => esc_html__( 'Footer Widgets', 'rx-theme' ),
'id' => 'footer-widgets',
'description' => esc_html__( 'Widgets displayed inside the footer menu area.', 'rx-theme' ),
'before_widget' => '<section id="%1$s" class="rx-footer-widget widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="rx-footer-widget__title">',
'after_title' => '</h3>',
)
);
}
}
add_action( 'widgets_init', 'rx_theme_register_footer_widgets' );
Call the footer menu file inside your footer.php like this:
<?php get_template_part( 'template-parts/footer/footer-menu' ); ?>
Add this basic CSS in style.css:
.rx-footer-menu {
background: #111827;
color: #f9fafb;
padding: 48px 20px 24px;
}
.rx-footer-menu a {
color: inherit;
text-decoration: none;
}
.rx-footer-menu a:hover,
.rx-footer-menu a:focus {
text-decoration: underline;
}
.rx-footer-menu__inner {
max-width: 1200px;
margin: 0 auto;
}
.rx-footer-menu__top {
display: grid;
grid-template-columns: 1.3fr 2fr 1fr;
gap: 32px;
}
.rx-footer-menu__columns {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 24px;
}
.rx-footer-menu__heading {
margin: 0 0 14px;
font-size: 16px;
font-weight: 700;
}
.rx-footer-menu__list,
.rx-footer-social__list,
.rx-footer-legal__list,
.rx-footer-contact__list {
list-style: none;
margin: 0;
padding: 0;
}
.rx-footer-menu__item,
.rx-footer-contact__item {
margin-bottom: 10px;
}
.rx-footer-menu__description {
color: #d1d5db;
line-height: 1.7;
}
.rx-footer-menu__bottom {
border-top: 1px solid rgba(255,255,255,0.12);
margin-top: 32px;
padding-top: 20px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
flex-wrap: wrap;
}
.rx-footer-legal__list {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
.rx-footer-social__list {
display: flex;
gap: 12px;
margin-top: 18px;
}
.rx-footer-social__link {
width: 36px;
height: 36px;
display: inline-flex;
align-items: center;
justify-content: center;
border: 1px solid rgba(255,255,255,0.2);
border-radius: 999px;
}
.rx-footer-menu__back-to-top {
width: 38px;
height: 38px;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 999px;
background: rgba(255,255,255,0.08);
}
.screen-reader-text {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 991px) {
.rx-footer-menu__top {
grid-template-columns: 1fr;
}
.rx-footer-menu__columns {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 575px) {
.rx-footer-menu__columns {
grid-template-columns: 1fr;
}
.rx-footer-menu__bottom {
align-items: flex-start;
flex-direction: column;
}
}
For social links, add this to functions.php and replace the URLs:
add_filter( 'rx_theme_footer_social_links', function( $links ) {
$links['facebook']['url'] = 'https://facebook.com/your-page';
$links['x']['url'] = 'https://x.com/your-profile';
$links['linkedin']['url'] = 'https://linkedin.com/in/your-profile';
$links['youtube']['url'] = 'https://youtube.com/@your-channel';
$links['github']['url'] = 'https://github.com/your-profile';
return $links;
} );
This footer menu file is safe, expandable, SEO-friendly, accessible, and ready for your advanced Rx Theme structure.