WordPress.org

Ready to get started?Download WordPress

Forums

Can the_excerpt grab post title? (9 posts)

  1. grovesk
    Member
    Posted 5 years ago #

    Hi - I want the_excert tag ti function as a read more tag, but grab the post title Is this possible? I need to set up for a client who doesn't want to have to fuss with the more tag each time he posts. (http://www.robertskrob.com).

    I thought this would work:

    <?php the_excerpt("...continue reading " . get_the_title('', '', false)); ?>

    Can someone tell me what I can do. Pls. note, I am not a php whizz, so need somewhat straight forward info.

  2. SteveSmith1983
    Member
    Posted 5 years ago #

    the_excerpt() doesn't do "read more" - you would have to create a link yourself, like this:

    <?php the_excerpt(); ?>
    <a href="<?php the_permalink(); ?>">continue reading...</a>

    Hope that helps!

  3. Roy
    Member
    Posted 5 years ago #

    He, I didn't know that. Going to try immediately!

    [edit], hmmm. The [...] are built in somewhere so they still appear and the "continue reading..." gets another font, so I'll have to have a look at my stylesheet. It's better than nothing though.

    (note: I use the Excerpt Editor plugin that can make excerpt everywhere but on the search results page.)

  4. grovesk
    Member
    Posted 5 years ago #

    Hi - Yes, definitely closer to what I was shooting for. Same issue as Gangleri though: would love to get rid of the [...]. Any suggestions? And still wondering if there a way to get the

      continue reading...
    , to pull the post title though? I am going to experiment abit but if anyone knows this already, let me know.

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    The wp_trim_excerpt function creates the excerpt from the original content unless you have a custom excerpt defined for that post. It is what adds the [...] text.

  6. grovesk
    Member
    Posted 5 years ago #

    OK, just seeking clarification: If I don't want to use a custom excerpt can I edit the wp_trim_excerpt to not use [...]? If so, where do I find the wp_trim_excerpt tag?

  7. SteveSmith1983
    Member
    Posted 5 years ago #

    wp_trim_excerpt() is defined in wp-includes/formatting.php, if you want to start hacking things off it ;) (commenting out line 857 will do the trick without causing any harm, I think).

    To pull the title use _the_title(), like this:

    <?php the_excerpt(); ?>
    <a href="<?php the_permalink(); ?>">Read more about <?php the_title(); ?></a>
  8. grovesk
    Member
    Posted 5 years ago #

    Brilliant! I now have the title showing.

    I found wp_trim_excerpt on line 821 in my wp-includes/formatting.php. The line I was interested in looks like this:
    array_push($words, '[...]');`

    Commenting out worked but then it shoved the Share this right up against the text. So I experimented. You can edit the anything inside the [] on line 821. I changed mine to read ' [...use link below to read more] '.

    See http://www.robertskrob.com

    Thanks to SteveSmith1983!

  9. SteveSmith1983
    Member
    Posted 5 years ago #

    Ah, yes - that's the line I was referring to. I'm glad you've got it how you want it! Happy to help.

Topic Closed

This topic has been closed to new replies.

About this Topic