WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] If the_title() echo into a HTML class (3 posts)

  1. Bennyjh
    Member
    Posted 1 year ago #

    Can't get this to work for some reason;

    <li><a href="#" class"<?php if (the_title()=='Home' { echo 'current-page'; } ?>">Home</a></li>

    Should I be using a different wordpress function? Any help would be appreciated.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Assuming that this is within the Loop, try:

    <li><a href="#" class"<?php if (get_the_title()=='Home' { echo 'current-page'; } ?>">Home</a></li>

  3. Bennyjh
    Member
    Posted 1 year ago #

    Thanks for the help, but I managed to get it working.

    For anyone interested;

    <li><a href="#" <?php if(is_page('Home')){ echo 'class="current-page" style="color:#FFF"'; } ?>>Home</a></li>

    You can also use is_front_page()

Topic Closed

This topic has been closed to new replies.

About this Topic