Skip Navigation

[Resolved] Showing empty p tags in views on the front end.

This thread is resolved. Here is a description of the problem and solution.

Problem:

I'm just wondering if any other solutions to this or why the filter affects wpv-post-body and wpv-post-excerpt in two different ways i.e. adding a paragraph to the post-excerpt and removing as expected from post-body?

Solution:

Shortcode [wpv-post-excerpt] does not apply filter hook "the_content" by default, unless it is retrieving data from post content when post excerpt is empty.

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-excerpt

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by lindsayH 4 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1375791
Code of Expert view.png
Excerpt view WITH filter.png

I referred to the solution in this ticket: https://toolset.com/forums/topic/manual-paragraphs-setting-showing-empty-p-tags-in-content-template-2/

Paragraphs were being added to the second item and all items following in the view.

In the view I tried using [wpv-noautop] [/wpv-noautop] shortcode (with content between) in the loop item, but didn't make any difference. I also tried the Output Editor.

Next I tried the function:

remove_filter( 'the_content', 'wpautop' );
 add_filter( 'the_content', 'wpautop' , 12);
  
add_filter('the_content', 'remove_empty_p', 20, 1);
function remove_empty_p($content){
    $content = force_balance_tags($content);
    return preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content);
}

This worked as expected on the view that was using,

[wpv-post-body view_template="None"]

But for views that are just using the excerpt it ended up adding a paragraph! See also images attached for this (this is ONLY when using the above filter).

Code used in the post excerpt view.

<a href="[wpv-post-url]">[wpv-post-featured-image size="blog"]</a>
<div style="text-align: center;">[wpv-post-link]</div>
[wpv-post-excerpt length="200"]
[wpv-post-read-more class="button btn-work-areas"]

If I remove the filter from functions.php then the above view returns to normal.

To solve I removed the filter and instead used the CSS as below on the page using the view with wpv-post-body. Using the empty pseudo selector (with another class to target the one page), immediately resolves my problem.

p:empty {
  display: none;
}

But I'm just wondering if any other solutions to this or why the filter affects wpv-post-body and wpv-post-excerpt in two different ways i.e. adding a paragraph to the post-excerpt and removing as expected from post-body?

#1376157

Hello,

In your screenshot:
https://toolset.com/wp-content/uploads/2019/11/1375791-Excerpt_view_WITH_filter.png

There is an extra HTML p tag above the post title, it seems to come from "the post excerpt view" codes:

<a href="[wpv-post-url]">[wpv-post-featured-image size="blog"]</a>
<div style="text-align: center;">[wpv-post-link]</div>

And there are some similar known issues when using Layouts plugin, for example:
https://toolset.com/forums/topic/i-have-a-problem-with-markup-in-wysiwyg-fields-that-get-shown-in-a-layout-2/
https://toolset.com/forums/topic/a-lot-of-closing-tags-that-didnt-correspond-to-any-opening-tags/

For the question:
But I'm just wondering if any other solutions to this or why the filter affects wpv-post-body and wpv-post-excerpt in two different ways

Shortcode [wpv-post-excerpt] does not apply filter hook "the_content" by default, unless it is retrieving data from post content when post excerpt is empty.

In my opinion, you don't need those custom PHP filter functions, for example, shortcode:
[wpv-post-excerpt], you can try attribute format="noautop", like this:

[wpv-post-excerpt length="200" format="noautop"]

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-excerpt
format (opt):
'autop' | 'noautop'
Controls whether the excerpt will be wrapped in paragraph tags or not. Defaults to autop.

#1376175

Many thanks. Seems that there is quite a bit being worked on.

Just to clarify if I do NOT use the custom PHP filter the post-excerpt works as expected, i.e. no extra paragraphs on the front end, so I don't need the attribute format="noautop". Thank you for the pointer though.

The custom PHP filter only corrects the extra paragraphs in my post-body views, but then if I use it it causes a problem with the post-excerpt views (I could look at adding the attribute format="noautop" to these if I chose to use the filter).

For me using the 'empty' pseudo selector in my CSS works well, so I'll stick with that.

Thank you for the explanation and the links showing me this is being worked on by your developers.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.