TPG Get Posts
[resolved] Fix links when char limit hits in the middle of a tag. (2 posts)

  1. Sam
    Posted 3 years ago #

    I run into a certain situation where the 'read more' link breaks.

    What's happening is when the word limit is reached and it's in the middle of a link.

    [tpg_get_posts fields="post_title, post_content" category_name="news" numberposts="4" show_entire="false" show_excerpt="true" shorten_content="w575" show_meta="false" more_link_text="Read More →"]

    So I've got text like this:

    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris <a href="test-link-here">nisi ut aliquip ex ea commodo consequat.</a>

    I'll get at the end
    ...laboris Read More
    but the Read More won't be linked. If you inspect the code, you'll see a broken a href tag with the link in it, like this:
    <a href="<a href="test...


  2. cswaim
    Plugin Author

    Posted 3 years ago #

    Yes, the shorten_content feature is risky as it either counts characters or words (defined by space separation) and trims the content when the limit is reached. It is not aware of html tags. It should only be be used when control over content is very controlled. Using the read-more tag is safer.

    I will update the doc to reflect this restriction.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • TPG Get Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.