• I am using a html menu in wordpress header and using twenty tweleve theme

    my problem is i need to active the menu item when the respective page is shown but below code is not working how can i make this work

    <?php
    if ( is_home() ) {
         <li class="active">
                                <a href="http://www.siteurl.com/shop/" class="active">
                                    <i class="icon-nav icon-home"></i>
                                    Home
                                </a>
                            </li>
    
    } else {
     <li>
                                <a href="http://www.siteurl.com/shop/" >
                                    <i class="icon-nav icon-home"></i>
                                    Home
                                </a>
                            </li>}
    ?>
    <?php
    if ( is_page(172) ) {
         <li class="active">
                                <a href="http://www.siteurl.com/shop/?page_id=172" class="active">
                                    <i class="icon-nav icon-star"></i>
                                    About </a>
                                                       </li>
    
    } else {
     <li>
                                <a href="http://www.siteurl.com/shop/?page_id=172">
                                    <i class="icon-nav icon-star"></i>
                                    About</a>
                                                       </li>
    												   }
    ?>
    <?php
    if ( is_page(176) ) {
         <li class="active">
                                <a href="http://www.siteurl.com/shop/?page_id=176" class="active">
                                    <i class="icon-nav icon-th-large"></i>
                                    Gallery</a>
                                                       </li>
    is
    
    } else {
     <li>
                                <a href="http://www.siteurl.com/shop/?page_id=176">
                                    <i class="icon-nav icon-th-large"></i>
                                    Gallery</a>
                                                       </li>
    }
    ?>
    <?php
    if ( is_page(174) ) {
        <li class="active">
                                <a href="http://www.siteurl.com/shop/?page_id=174" class="active">
                                    <i class="icon-nav icon-comments"></i>
                                    Services</a>
    								</li>
    
    } else {
     <li>
                                <a href="http://www.siteurl.com/shop/?page_id=174">
                                    <i class="icon-nav icon-comments"></i>
                                    Services</a>
    								</li>
    								}
    ?>
    <?php
    if ( is_page(2) ) {
        <li class="active">
                                <a href="http://www.siteurl.com/shop/?page_id=2" class="active">
                                    <i class="icon-nav icon-shopping-cart"></i>
                                    Shop</a>
                                                       </li>
    
    } else {
     <li>
                                <a href="http://www.siteurl.com/shop/?page_id=2">
                                    <i class="icon-nav icon-shopping-cart"></i>
                                    Shop</a>
                                                       </li>
    												   }
    ?>
    <?php
    if ( is_page(187) ) {
        					<li class="active">
                                <a href="http://www.siteurl.com/shop/?page_id=187" class="active">
                                    <i class="icon-nav icon-pencil"></i>
                                    Blog</a></li>
    
    } else {
     					<li>
                                <a href="http://www.siteurl.com/shop/?page_id=187">
                                    <i class="icon-nav icon-pencil"></i>
                                    Blog</a></li>
    
    												   }
    ?>
    <?php
    if ( is_page(145) ) {
        <li class="active">
                                <a href="http://www.siteurl.com/shop/?page_id=145" class="active">
                                    <i class="icon-nav icon-plus-sign"></i>
                                    Events</a></li>
    
    } else {
    <li>
                                <a href="http://www.siteurl.com/shop/?page_id=145">
                                    <i class="icon-nav icon-plus-sign"></i>
                                    Events</a></li>
    												   }
    ?>
    <?php
    if ( is_page(178) ) {
        <li class="active">
                                <a href="http://www.siteurl.com/shop/?page_id=178" class="active">
                                    <i class="icon-nav icon-map-marker"></i>
                                    Contact</a>
    
                            </li>
    
    } else {
     <li>
                                <a href="http://www.siteurl.com/shop/?page_id=178">
                                    <i class="icon-nav icon-map-marker"></i>
                                    Contact</a>
    
                            </li>
    												   }
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Why aren’t you using wp_nav_menu? And do not edit the Twenty Eleven theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. First create a child theme for your changes. Or use a custom CSS plugin.

    Thread Starter surya300

    (@surya300)

    no i am using twenty twelve not twenty eleven

    because i was not able to code correctly for icons that should be displayed above

    so i am directly using the html

    i am using twenty twelve not twenty eleven

    Then do not edit the Twenty Twelve theme. Create a child theme for your changes.

    because i was not able to code correctly for icons that should be displayed above

    Why? That’s pure CSS.

    after having created the child theme, make sure to use a proper php/html syntax; i.e. close the php tags before switching over to htmll, and open them again when switching back to php;

    example shown for the first li element code:

    <?php
    if ( is_home() ) { ?>
         <li class="active">
                                <a href="http://www.siteurl.com/shop/" class="active">
                                    <i class="icon-nav icon-home"></i>
                                    Home
                                </a>
                            </li>
    
    <?php } else { ?>
     <li>
                                <a href="http://www.siteurl.com/shop/" >
                                    <i class="icon-nav icon-home"></i>
                                    Home
                                </a>
                            </li>
    <?php } ?>

    you could also simplify this section to:

    <li <?php if ( is_home() ) echo 'class="active"'; ?>>
                 <a href="http://www.siteurl.com/shop/" class="active">
                          <i class="icon-nav icon-home"></i>
                           Home
                      </a>
                </li>
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘conditional tags error’ is closed to new replies.