How to make a WordPress menu tag a. Code example open

How to make a WordPress menu tag a. Code example

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators
Tested: WordPress 4.0+, PHP 5.6 +

By default wp_nav_menu function, show menu items in the list view li, for change them to the link a tags change your wp_nav_menu function as shown in the example below.

<?php 

echo strip_tags(wp_nav_menu(
    array(
        'theme_location' => 'header_nav',
        'container' => false,
        'echo' => false,
        'items_wrap' => '%3$s',
        'depth' => 0
    )
    ),'<a>');

?>

This code displays the navigation menu defined for the header_nav area, without using a container. The echo option is set to false to prevent the wp_nav_menu() function from printing the result directly, but instead returning it as a string. The items_wrap option sets the wrapping format for menu items. The depth option is set to 0 to display only the first level menu items. The strip_tags() function is used to strip all HTML tags except the tag from the rendered menu before echoing it.

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation