Active menu class not working in wordpress - wordpress

I am developing my own theme (using the functions of Twenty Fourteen (nothing has changed in functions.php)). My header does not contain wp_head() but I am using body_class() in my body tag. My menu is defined as so:
<?php
$menuParameters = array(
'container' => false,
'echo' => false,
'items_wrap' => '%3$s',
'depth' => 0,
);
echo strip_tags(wp_nav_menu( $menuParameters ), '<a>' );
?>
Unfortunately, my current-menu-item is not being applied to my navigation anchors when on a wordpress-created page. Am I missing a function somewhere that renders this class? Thanks in advance?

<?php wp_nav_menu(array(
'container'=> '',
'menu_class' => '',
'menu_id' => '',
)); ?>

Related

WordPress navigation menu is not loading

I am working on my custom theme in wordpress, I have a problem in the navigation in my site, when I open the site, the main navigation is not loading.
Below are the codes.
Any assistance is highly appreciated.
Thanks.
Function.php file
function register_my_menus() {
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary', 'nethub' ),
) );
}
add_action( 'init', 'register_my_menus' );
Then in header.php the code is
<?php
wp_nav_menu(
array(
'theme_location' => 'menu-1',
'menu' => 'primary-menu',
'container' => false,
'items_wrap' => '<ul class="rd-navbar-nav">%3$s</ul>',
)
);
?>
</div>
Have you created a menu in the menus edit screen and set it to the "Primary" location? Also think you can remove the 'menu' => 'primary-menu', from your header.php:
// header.php
<?php
wp_nav_menu(array(
'theme_location' => 'menu-1',
'container' => false,
'items_wrap' => '<ul class="rd-navbar-nav">%3$s</ul>',
));
?>
</div>

How to style <?php html5blank_nav(); ?> in functions.php

I've used a HTML 5 Blank template and converted it to a WordPress theme successfully.
But when I use this code: <?php html5blank_nav(); ?> to auto populate the main navigation it of course looses the template styling.
I've enqueued all the css but from what I understand I need to use the below code to tell the menu how to be styled:
PHP:
function html5blank_nav()
{
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
If you take a look at http://geekcloud.co.uk - this is the header navigation menu style im trying to achieve using this code: .
Any help would be greatly appreciated.
Thank you.
You might want to look into the wp_enqueue_style page on the Wordpress developer documentation.
You have to register the stylesheet in your functions.php file with
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Good luck developing!

how to add custom wordpress Menu using just A tag output

I want to create menu like below code but wordpress generate other code.
help me to generate code like below HTML code
Thanks in advance.
help me to generate below code using wordpress
You can do this by using menu walker class like this:
wp_nav_menu( array(
'container' => false,
'menu' => 'main-menu',
'menu_class' => 'nav navbar_menu',
'walker' => new Custom_Walker_Nav_Menu
)
);
add_theme_support('menu');
function register_newtheme_menu(){
register_nav_menus(
array(
'main-menu'=>_('Main Menu')
)
);
}
add_action('init','register_newtheme_menu');
function add_menuclass($ulclass) {
return preg_replace('/<a /', '<a class="navigation-link w-nav-link" ', $ulclass);
}
add_filter('wp_nav_menu','add_menuclass');
?>
<nav class="menu-hamburger w-nav-menu" role="navigation">
<?php
$defaults = array(
'container' => 'false',
'echo' => false,
'fallback_cb' => false,
//'items_wrap' => '<a id="%1$s" class="%2$s">%3$s</a>',
'depth' => 0
);
//echo wp_nav_menu( $defaults );
echo strip_tags(wp_nav_menu( $defaults ),'<a>');
?>
</nav>

Where/What is the wordpress function that outputs the menus?

Looking at the Wordpress code I am struggling to find where the menus are been put together, (to be rendered).
For example, if I want to output 'menu-1' where is the function/class that creates the output result?
Does it use a class to do the creation? Does it follow a specific pattern?
Walker_Nav_Menu And wp_nav_menu is behind the wordpress Navigation. According to your requirement you need to customize the wp_nav_menu
$defaults = array(
'theme_location' => '',
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'depth' => 0,
'walker' => ''
);
wp_nav_menu( $defaults );
For adding the custom menu option that allows users to add and organize menus, you'll add this in your function.php
add_theme_support( 'menus' );
And then you can paste this code anywhere you want to display the custom menu
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
the wp_nav_menu is the main function that displays menus on the WordPress page with a few arguments stored as an array. Sort_column instructs WordPress to follow the order in the options, and the container_class :.menu-header is the CSS class to style this menu. For displaying multiple menus, you can specify the id, slug, menu name with $id, $slug, $menu

clean up wordpress custom navigation

i have made a custom menu named "header-menu" and i call it in my header.php:
<?php wp_nav_menu( array(
'container' => '',
'theme_location' => 'header-menu'
) ); ?>
with
'container' => '',
i want to remove the menu wrapper, but the output still has this:
<div class="menu">
<ul>
<li> ... </li>
<li> ... </li>
</ul>
</div>
but i want to get rid of the annoying
<div class="menu">
. how to do that?
It's not clear what you're actually doing here but if you want the container to go away you use:
<?php wp_nav_menu( array(
'container' => false,
) ); ?>
Review this page for more detail.
got it working now:
<?php $defaults = array(
'theme_location' => '',
'menu' => 'footer-menu',
'container' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'items_wrap' => '<ul class="dl-menu">%3$s</ul>',
'depth' => 2
);
wp_nav_menu( $defaults );
?>

Resources