WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add text to navigation bar Twenty Eleven theme (7 posts)

  1. TimoElshof
    Member
    Posted 2 years ago #

    Hello,

    I want to add a text (a phonenumber, to be more specific) to the navigation bar in the Twenty Eleven theme of my site: http://www.timoelshof.nl I work in a child's theme of course ;-) Can somebody help?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Try it with this in your childtheme's functions.php:

    add_filter( 'wp_nav_menu_items', 'add_telephone_number', 10, 2 );
    function add_telephone_number($items, $args) {
    
        return $items . '<li class="menu-item telephone">' . $args->before . 'tel: 456 777 8347' . $args->after .'</li>';
    }

    and change 'tel: 456 777 8347' to the correct number.

    And put this in your child theme's stylesheet (style.css):

    #access li.telephone {
        color: #EEEEEE;
        display: block;
        line-height: 3.333em;
        padding: 0 1.2125em;
        text-decoration: none;
    }
  3. TimoElshof
    Member
    Posted 2 years ago #

    Thanks, you're a star! One more question; how can I algin the phonenumber to the right?

  4. TimoElshof
    Member
    Posted 2 years ago #

    algin = align ;-)

  5. keesiemeijer
    moderator
    Posted 2 years ago #

    Try adding float: right; to the #access li.telephone css declaration and test it in all major browsers.

  6. TimoElshof
    Member
    Posted 2 years ago #

    Brilliant, thanks!

  7. JohnVlahos
    Member
    Posted 1 year ago #

    Hello,

    I've tried this and I must be missing something because my phone number is not displaying in the nav bar. Any ideas?

    Code from fuctions.php

    add_filter( 'wp_nav_menu_items', 'add_telephone_number', 10, 2 );
    function add_telephone_number($items, $args) {

    return $items . '<li class="menu-item telephone">' . $args->before . 'tel: 999 999 9999' . $args->after .'';
    }

    Code from css

    #access li.telephone {
    color: #ffffff;
    display: block;
    line-height: 3.333em;
    padding: 0 1.2125em;
    text-decoration: none;
    float: right;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic