• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Hardcode nav

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Hardcode nav

This topic is: not resolved

Tagged: hardcode, html, nav

  • This topic has 3 replies, 2 voices, and was last updated 10 years, 10 months ago by yogidev.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • February 12, 2015 at 7:35 am #140584
    yogidev
    Member

    Hi,

    I am maintaining and developing a site for a client.
    They don't need control of the nav, only content. and I would like to have lots of control over the nav html.
    So, basically, I want to hardcode the whole nav section.

    This is turning out to be not so easy as I am new to PHP and theming.

    I could create a widget but that's kind of messy and unsemantic.

    Can anyone share an easy way to replace the nav with a custom template?
    Inside that template can be static HTML.

    February 15, 2015 at 6:36 am #140909
    Brad Dalton
    Participant

    You can use a custom walker class

    Or

    Filter the wp_nav_menu function http://codex.wordpress.org/Function_Reference/wp_nav_menu


    Tutorials for StudioPress Themes.

    February 27, 2015 at 1:15 pm #142558
    yogidev
    Member

    Hi, thanks for the reply.

    I looked up walker classes and I don't see how that could work.

    Here is the site in development:

    http://sulekhruparell.yanwhite.com/about/

    Each item needs to have this kind of content:

    <li><a>
    <em>About</em>
    <span>A bit about me</span>
    </a></li>

    Is there a way to do that? It seems an extra field would need to appear in the admin menu area, which is why I just hardcoded it.

    February 27, 2015 at 1:53 pm #142566
    yogidev
    Member

    Ah I hadn't realised the description is a hidden option in admin menu area.

    I managed to find this code which is working:

    // Menu with Description
    
    class Menu_With_Description extends Walker_Nav_Menu {
        function start_el(&$output, $item, $depth, $args) {
            global $wp_query;
    
            $indent = ( $depth ) ? str_repeat( " ", $depth ) : '';
    
            $class_names = $value = '';
    
            $classes = empty( $item->classes ) ? array() : (array) $item->classes;
    
            $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
            $class_names = ' class="' . esc_attr( $class_names ) . '"';
    
            $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
    
            $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
            $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
            $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
            $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
    
    		// get user defined attributes for thumbnail images
    		$attr_defaults = array( 'class' => 'nav_thumb' , 'alt' => esc_attr( $item->attr_title ) , 'title' => esc_attr( $item->attr_title ) );
    		$attr = isset( $args->thumbnail_attr ) ? $args->thumbnail_attr : '';
    		$attr = wp_parse_args( $attr , $attr_defaults );
    
            $item_output = $args->before;
    
    		// thumbnail image output
    		$item_output .= ( isset( $args->thumbnail_link ) && $args->thumbnail_link ) ? '<a' . $attributes . '>' : '';
    		$item_output .= apply_filters( 'menu_item_thumbnail' , ( isset( $args->thumbnail ) && $args->thumbnail ) ? get_the_post_thumbnail( $item->object_id , ( isset( $args->thumbnail_size ) ) ? $args->thumbnail_size : 'thumbnail' , $attr ) : '' , $item , $args , $depth );		
    		$item_output .= ( isset( $args->thumbnail_link ) && $args->thumbnail_link ) ? '</a>' : '';
    
    		// menu link output
            $item_output .= '<a'. $attributes .'>';
            $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
    
    		// menu description output based on depth
            $item_output .= ( $args->desc_depth >= $depth ) ? '<br /><span class="sub">' . $item->description . '</span>' : '';
    
    		// close menu link anchor
            $item_output .= '</a>';
            $item_output .= $args->after;
    
            $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
        }
    }
    
    add_filter( 'wp_nav_menu_args' , 'my_add_menu_descriptions' );
    function my_add_menu_descriptions( $args ) {
    	$args['walker'] = new Menu_With_Description;
    	$args['desc_depth'] = 0;
    	$args['thumbnail'] = true;
    	$args['thumbnail_link'] = false;
    	$args['thumbnail_size'] = 'nav_thumb';
    	$args['thumbnail_attr'] = array( 'class' => 'nav_thumb my_thumb' , 'alt' => 'test' , 'title' => 'test' );
    
    	return $args;
    }
    
  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble