• I developed a theme and I wish to create a filters to properly truncate tables in excerpt. In fact, I have several posts containing long tables (several dozen rows), and I wish that, as an excerpt is requested, for example in a category page, only few rows are shown. How could I do that?

    Thank you in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure why t-p thinks you are trying to fix a commercial theme, they may have made the correct reply to the wrong post. Mistakes happen, don’t worry about it.

    Excerpts are truncated by wp_trim_excerpt(). Hook the filter of the same name and see if table tags appear in the excerpt. If so, the raw content was passed as a second parameter. Starting from where the function first truncated the output, search forward until a </tr> tag is encountered. It’s safe to truncate a table after this tag since it represents the end of a row. Append a </table> tag to close out the shortened table. Return the modified excerpt.

    To be 100% correct, there may be more table tags to close out like tbody, and other legitimate row ends, like </th> or <tfoot>. Browsers tend to be forgiving of malformed HTML, but if you want your output to validate, all possible scenarios need to be accounted for.

    Moderator t-p

    (@t-p)

    Looks like I pasted my reply in a wrong post. Sorry!I archived my reply. Thanks for letting me know.

    Thread Starter dejudicibus

    (@dejudicibus)

    ok, thank you. MY theme is not commercial at all, by the way. It’s a personal theme. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Trucating tables in excerpt’ is closed to new replies.