• Wow I feel dumb that I can’t figure this out but I can’t….

    On my tags pages I show the auto generated 55 word excerpt. 3 posts per tags page.

    How do I show a “read more” tag that links to the post title rather than just the […..] after the auto generated excerpt?

    It seems like a bad user experience to make people realize they need to click the post title to read more.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter flashpacker

    (@flashpacker)

    thanks for that doesn’t work for me. I already tried it.

    I don’t find the info in the codex particularly clear (for this) but isn’t that for the read more tag that is manually inserted into posts?

    I might be completely wrong but I was trying to figure out why it wasn’t working and that was what I came up with. Could that be the issue?

    details might vary between themes.

    you are using the_excerpt(); in your templates;

    and adding the code from this link https://codex.www.ads-software.com/Function_Reference/the_excerpt#Make_the_.22read_more.22_link_to_the_post to functions.php of your theme does not change the [...] into a link to ‘read more’?

    what is changing, if anything, when you do the above?

    what theme are you using?

    Thread Starter flashpacker

    (@flashpacker)

    So the other problem could be that I’m using the custom function below.
    Could that be what the problem is? (It’s a custom theme too)

    I was thinking that get_the_excerpt and the excerpt_more functions were different but the is the other possibility is that this is what’s stopping it working.

    Thanks for your help ?? Really appreciate a random stranger trying to help!

    [code moderated - please check the guidelines for posting code - https://codex.www.ads-software.com/Forum_Welcome#Posting_Code ]

    using the custom function below.
    Could that be what the problem is?

    yes – the custom function is not replicating the filter hoooks that the original wp_trim_excerpt() function has.

    once you pasted the code of that custom function into a https://pastebin.com/ and posted the link to it here, i’ll have a look.

    Thread Starter flashpacker

    (@flashpacker)

    Thanks so much!

    Paste bin –
    https://pastebin.com/Kbmi6Hg1

    The main reason for using the custom function is so excerpts retain the <p> styling.

    Thread Starter flashpacker

    (@flashpacker)

    … the para, strong and link styling. I obviously needed to read the info on posting code!

    one possibility – to add the code to work with the filters for excerpt length and read-more:
    https://pastebin.com/4BLe1AKh

    other possibility – to add the read-more link directly ito the function:
    https://pastebin.com/XcMpj6QV

    (both untested)

    caveat: the way of conserving some html tags in the excerpt before shortening the code can lead to unclosed html tags, and therefore to unexpected display problems and invalid html code.
    there are some quite complicated codes out there to close these html tags automatically; for instance (untested)
    if you want to follow up on that, search the web for ‘php close html tags automatically’ or similar

    Thread Starter flashpacker

    (@flashpacker)

    Thanks for your help!

    The first one results in only the title being shown unless a more tag is used in the post. If a more tag is used, the excerpt shows, but no tag or even dots show, its just blank after the excerpt.

    The second one works for a static excerpt length and text, but I want to be able to use different more text on each post (for SEO purposes) and vary the length to enticing people to read purposes.

    Thanks for the info about the other problem. I’d noticed problems with strong tags not being closed and the whole rest of the page being in bold!

    I know the code I showed you had excerpt at 55 but I actually show a much longer excerpt so that short posts appear in full and only super long posts get cut off, which is partly why I don’t want to lose the styling.
    I’d changed it back to 55 while I was testing some stuff out.

    Any ideas on how to get the first option to actually show the more text I have included in the tag, and to show a default length excerpt if no more tag is used?

    The second one works for a static excerpt length and text, but I want to be able to use different more text on each post (for SEO purposes) and vary the length to enticing people to read purposes.

    how do you actually use the code from the function in the pastebin https://pastebin.com/Kbmi6Hg1 ?

    you might be able to pass the length as a second parameter….

    Thread Starter flashpacker

    (@flashpacker)

    Sorry I don’t follow? I just pasted the new version into my functions.php? Did you mean something else? ??

    Thread Starter flashpacker

    (@flashpacker)

    ok maybe you meant….

    I use it on my tag pages, which I use instead of categories or date archives as the main archives.

    I show 3 posts per page. Some are short 300 word ish posts, and others are 1200 words ish posts.

    Without any styling the excerpts are unreadable because lines run together etc.

    I just pasted the new version into my functions.php? Did you mean something else? ??

    are you calling this function directly in your template?
    for example:
    <?php echo improved_trim_excerpt(get_the_content()); ?>

    or are you using lines like these in functions.php:

    remove_filter('get_the_excerpt', 'improved_trim_excerpt')
    add_filter('get_the_excerpt', 'improved_trim_excerpt');

    ?

    Thread Starter flashpacker

    (@flashpacker)

    the latter. I really appreciate you helping out ??

    I want to be able to use different more text on each post (for SEO purposes) and vary the length to enticing people to read purposes.

    Any ideas on how to get the first option to actually show the more text I have included in the tag, and to show a default length excerpt if no more tag is used?

    imho, that is not possible with using the_excerpt – not even with a custom trim function.

    you possibly need to create a totally new function for this, possibly building on ‘$post->post_content’, finding the ‘more-tag’ position, getting the ‘more text’, stripping most html tags, etc.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Showing a read more tag after the auto generated excerpt.’ is closed to new replies.