Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin tommcfarlin/fallback-cb.php Secret
Created Feb 18, 2014

Embed
What would you like to do?
[WordPress] How to programmatically set a default menu in WordPress.
<?php
/**
* Provides a default menu featuring the 'Home' link, if not other menu has been provided.
*
* @package Acme
* @subpackage inc
* @version 1.0.0
* @since 1.0.0
*/
function acme_default_menu() {
$html = '<ul id="acme-default-menu">';
$html .= '<li class="menu-item menu-item-type-post_type menu-item-object-page">';
$html .= '<a href="' . esc_url( home_url() ) . '" title="' . __( 'Home', 'acme' ) . '">';
$html .= __( 'Home', 'acme' );
$html .= '</a>';
$html .= '</li>';
$html .= '</ul>';
echo $html;
} // end acme_default_menu
<?php
wp_nav_menu(
array(
'theme_location' => 'main',
'fallback_cb' => 'acme_default_menu'
)
);
<?php
wp_nav_menu(
array(
'theme_location' => 'main'
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.