I'm trying to install a Google AdWords snippet on a client website. It calls for replacing the business phonenumber on the page with something like

<span class="number">content</span>

The problem is that the phone number is listed in a wordpress menu at the top of the page. I can't exactly drop the code snippet into the frontend (Appearance->Menus). How can I integrate this span into the menu?

I got some advice in IRC to check out this these links: http://pastebin.com/9SJCK1Rh http://www.wpbeginner.com/wp-themes/how-to-add-custom-items-to-specific-wordpress-menus/

I'm still not sure how to apply this knowledge, though. Can someone elaborate on what I need to do to add this custom menu content? I need to use add_filter in a file somewhere in order to hook a function to wp_nav_menu_items, then use the function to test if it's the right menu and return the content that I want to go into the menu?

Urgent help needed!

1 Answer 1


For inject <span> into menu, you do it using below code:

//Setup this code into your current function.php file
add_filter('wp_nav_menu_items','add_span_in_menu', 10, 2);
function add_span_in_menu( $items, $args ) {
    if( $args->theme_location == 'primary')  {

        $myContent = 'YOURCONTENT'
        $items .=  '<li><span class="number">' . $myContent .  '</span></li>';

    return $items;

Above snippet will add <span> with content to your WordPress menu. Hope this help you well!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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