Ready to get started?Download WordPress


[resolved] Turning the_title into a css class (8 posts)

  1. yaphi
    Posted 5 years ago #

    I need to turn "About us" into "aboutus" so I went ahead and tried what many have posted here:


    What definitely doesn't work. Next I tried:

    print trim(strtolower(the_title_attribute('echo=0'))));

    And that still doesn't work. How can I achieve this?

  2. esmi
    Forum Moderator
    Posted 5 years ago #

    Try <?php str_replace(' ','',strtolower(the_title_attribute('echo=0'))); ?>

  3. t31os
    Posted 5 years ago #

    You can also use the_title('','',false); to prevent the value being returned.

    Just a little easier to write... :)

  4. esmi
    Forum Moderator
    Posted 5 years ago #

    But if you use the_title, you'll need to strip off the tags, won't you? That's why I thought using the_title_attribute might be a better approach.

  5. t31os
    Posted 5 years ago #

    Nope, if you set to false it just gives you the title without <a> links.


  6. yaphi
    Posted 5 years ago #

    Ahh...I misunderstood trim(). Thanks everyone I got it.

  7. yaphi
    Posted 5 years ago #

    Oh and for anyone that stumbled upon this, here was the code

    <h2 class="<?php print strtolower(str_replace(' ','', get_the_title($post->post_parent))); ?>"><?php echo get_the_title($post->post_parent); ?></h2>

    This prints an <h2> with a class of the parent's page title...so if you were on About Us / Contact or something,

    <h2 class="aboutus">About us</h2>

    that way I can replace it with an image.

  8. egoldin
    Posted 4 years ago #

    This was exactly what I needed! I changed it slightly to pull the current page title, instead of the parent and to only show on pages besides the front page:

    <?php if (!is_front_page()) print strtolower(str_replace(' ','', get_the_title($post))); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic