-4
\$\begingroup\$

How would I properly indent this code in PHP (I'm using WordPress)? I'm mostly concerned about how the <button> comes into this equation @ items_wrap.

<?php
if (has_nav_menu('primary_navigation')) :
  wp_nav_menu( array(
      'theme_location'    =>  'primary_navigation',
      'container'         =>  'nav',
      'container_class'   =>  'nav-primary',
      'menu_class'        =>  'nav toggleable hide',
      'items_wrap'        =>  '<button class="dropdown-toggle script-dependant">'.__('Menu', 'yolk').'</button><ul id="%1$s" class="%2$s">%3$s</ul>',
      'walker'            =>  new detailed_navigational_menu_walker
  ) );
endif;
?>
\$\endgroup\$
1
\$\begingroup\$

I would consider going ahead and defining some variables to make this configuration more easy to read. I also prefer to keep lines of code to the often recommended ~80 characters per line limit. Use concatenation to break up long strings across lines.

Perhaps something like this:

<?php
if (has_nav_menu('primary_navigation')) :
    $nav_menu_config = array(
        'theme_location'    =>  'primary_navigation',
        'container'         =>  'nav',
        'container_class'   =>  'nav-primary',
        'menu_class'        =>  'nav toggleable hide',
        'items_wrap'        =>
            '<button class="dropdown-toggle script-dependant">' .
            __('Menu', 'yolk') . '</button>' .
            '<ul id="%1$s" class="%2$s">%3$s</ul>',
        'walker'            =>  new detailed_navigational_menu_walker  
    );            
    wp_nav_menu($nav_menu_config);
endif;
?>
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.