WordPress.org

Ready to get started?Download WordPress

Forums

Shorten the_title() (5 posts)

  1. lilmousiee
    Member
    Posted 1 year ago #

    I am trying this on the_title():

    <?php substr(the_title('', '', FALSE), 0, 22); ?>..

    However it won't work.. It doesn't show the title at all, but when I do this:

    <?php substr(the_title(), 0, 22); ?>..

    It shows the title, but doesn't shorten it. I need to show only the first 22 characters.. How do I go about doing that?..

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    you need to echo the substr:

    <?php echo substr(the_title('', '', FALSE), 0, 22); ?>

  3. lilmousiee
    Member
    Posted 1 year ago #

    Ah wow.. thanks. I should have caught that >.<

  4. lilmousiee
    Member
    Posted 1 year ago #

    Do you have any idea on how to do that with the_content as well? I know it accepts two parameters. Right now I have '', FALSE and it doesn't strip them and I am echoing it out.

  5. lilmousiee
    Member
    Posted 1 year ago #

    Figured it out.

    function custom_excerpt_length($length) {
    	return 30;
    }
    add_filter('excerpt_length', 'custom_excerpt_length', 999);

Topic Closed

This topic has been closed to new replies.

About this Topic