Line Breaks are stripped off when direction property is found

The line breaks are stripped off when the p tag has a dir attribute inserted, to explain further I'll list some examples. Let's say we have 2 lines of text as following <p>Text Paragraph Number One Goes Here</p> <p>Text Paragraph Number Two Goes Here</p> If I want to add line breaks between the two paragraphs it works fine to become like: <p>Text Paragraph Number One Goes Here</p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p>Text Paragraph Number Two Goes Here</p> However if …
Category: Web

How to disable auto-p in WordPress?

I need to remove the "wpautop filter" from my WordPress Website because it is adding too many paragraphs. I'm new to WordPress. I don't know how to create Child themes. The name of my theme is the "supreme directory". is it also possible to remove the "wpautop filter" from the supreme directory theme directly?
Category: Web

How to call a PHP function in WordPress when you click on a button?

How to process the textarea field with the standard WordPress function wpautop() when clicking the button? Here's the form: <textarea id="my_ta">Lorem ipsum!</textarea> <button id="button_processing_ta">Обработать</button> Here's the handler (to function.php): <?php function my_action_javascript() { ?> <script> document.getElementById( 'button_processing_ta' ).addEventListener( 'click', function() { let my_ta = document.getElementById( 'my_ta' ); // ??? wpautop( my_ta.value ); }); </script> <?php } add_action( 'admin_print_footer_scripts', 'my_action_javascript', 99 ); ?> Sorry for my English...
Category: Web

Remove empty p-Tags in Shortcode content before non p-Tags

We build a media (based on bootstrap 4 media object) shortcode with the following syntax: [media img="https://via.placeholder.com/64x64.png"]<h5>List-based media object</h5>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.[/media] The function can be found here: add_shortcode( 'media', 'xcore_shortcode_media' ); /** * Media shortcode * * @doc https://getbootstrap.com/docs/4.3/components/media-object/ * * @param $atts * @param null …
Category: Web

remove empty paragraphs from the_content?

Hey guys, I simply want to prevent the creation of empty paragraphs in my wordpress post. That happens quite often when trying to manually space content. I don't know why this doesn't take effect? /*Remove empty paragraph tags from the_content*/ function removeEmptyParagraphs($content) { /*$pattern = "/<p[^>]*><\\/p[^>]*>/"; $content = preg_replace($pattern, '', $content);*/ $content = str_replace("<p></p>","",$content); return $content; } add_filter('the_content', 'removeEmptyParagraphs'); edit/update: seems like the problem is this: function qanda($content) { // filters for [q=some question] and [a=some answer] // wraps it …
Category: Web

Disable wpautop on Shortcode attributes

I have a shortcode which accepts basic HTML tags as shortcode attribute. When this shortcode is used in the shortcode block i.e within <!-- wp:shortcode --> then unbalanced <p> tags are added to the shortcode attribute. If it is used normally, then no <p> tags are added. Are there any workarounds which can be done to avoid this issue ? function abcd_shortcode( $atts ){ print_r( $atts ); } add_shortcode('abcd', 'abcd_shortcode'); Output (notice the </p> and <p> tags added for no …
Category: Web

New method to disable wpautop after WP 4.3?

After WordPress 4.3, the old method of disabling wpautop no longer works. Has anyone discovered a new method for removing this function? remove_filter( 'the_content', 'wpautop', 99 ); remove_filter( 'the_excerpt', 'wpautop', 99 );
Category: Web

Removing "wpautop" (auto <p> tags) only on certain pages?

I'm using the remove_filter in functions.php to remove the auto insertion of &lt;p&gt; and &lt;br&gt; tags on my wordpress site. remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); But one of our pages (wiki) is being dynamically created and to make a long story short, it relies on the &lt;p&gt; tags. How and where should I write an if statement that targets only certain pages to apply the remove_filter to? I've tried placing this code in the both the functions.php, …
Category: Web

Remove wpautop from shortcode content / remove whitespace in buffering

I am using the Mailchimp plugin, and it has a shortcode that uses output buffering to grab its widget's code and spit it out in the content. However, the widget code has plenty of white space, so the_content filters are throwing useless linebreaks (like after hidden inputs) and empty p tags everywhere... rendering it unusable. I am removing the shortcode to add my own, but I'm not sure what to do to prevent the WordPress wpautop filter from going crazy. …
Category: Web

wpautop is not working when displaying content saved using wp_editor in a custom meta box

I am using wp_editor in a custom meta box. It is saving the content to the post metadata. And displaying it in the meta box as it should. The problem is when I am trying to display this content on the public-facing side of the website. It is displaying without the paragraphs. All other HTML that are part of the wp_editor content is displaying as they should. My meta box code is as follows: public static function as_bllp_create_call_to_action_meta_box( $post ){ …
Category: Web

Removing line breaks when in text view with wp_editor

While working on a custom plugin, I needed to add the wp_editor in the admin to let the user add its own content. I want the user to be able to write custom rich texts with the "Visual" editor mode but I also want the user to be able to paste HTML codes in the "Text" view. For example, if he wants to paste his subscription HTML form, he could do that while switching to the "Text" mode. The issue …
Category: Web

Wordpress not saving <p> tags for custom taxonomy term description

I'm using wordpress API to display content. I'm using the classic editor since guttenberg is bugging out elsewhere. I noticed that if a paragraph does not have inline styles, wordpress does not save the &lt;p&gt; tags in the database. So when I call the api, the response is something like this: first paragraph. second paragraph. There isn't even a &lt;br&gt; tag in between, just a newline I believe. I just need to style paragraphs to be spaced apart, so I …
Category: Web

Shortcodes within the sidebar text/html widget: How to preserve the raw HTML output of the shortcode?

WordPress 5.2 destroys structured data by adding rel="noopener noreferrer" to widget output (also to shortcodes): How to display the shortcode output without code change? This feature was added in 5.2: https://core.trac.wordpress.org/ticket/43280 Basically there is nothing wrong with adding rel="noopener noreferrer" to &lt;a href="..." target="_blank"&gt;&lt;/a&gt; links, as it will protect from malicious comments or bad authors for instance. Anyway I have a shortcode from some plugin which is generating structured data (rating stars) for a website and embedded via shortcode. Adding …
Category: Web

WooCommerce Description and Short Description <p> tags removal

When adding content into the description and short description fields for a product, line-breaks and tags are completely removed from the markup. Other than installing Advanced TinyMCE, is there any setting, filter, or hook I need to check to make these fields include elements. In review of the Product object array in WooCommerce, it looks like the value for description is wrapped in the wpautop() function, but it doesn't appear to be working (it's possibly I'm just not understanding this …
Category: Web

How to automatically add paragraph tags in the Visual Editor

From my Googling, it appears as though the default behavior in Wordpress is to add paragraphs automatically, but in the HTML view, regardless of what style I choose in the Visual Editor's style drop-down (paragraph, for example), paragraph tags never appear. I also do not see wpautop() called anywhere in my theme (which I inherited from a now departed developer). What can I do to set this straight? Adding &lt;p&gt; tags to everything is obviously not going to fly with …
Category: Web

Images that copy code to clipboard when you click on them

I run a website about a programming language which is very well-integrated with a front-end which adds a lot of styling to the code that cannot be replicated in the browser. For that reason, I publish my tutorials by having blocks of text interspersed with images of code. Clicking on the images copies the code to the clipboard so that people can use them in their own front-end. Here is what the HTML code for this looks like: &lt;img src="..." …
Category: Web

How do I disable wpautop for a specific block?

I've registered a custom editor block with Advanced Custom Fields (ACF), and am using render_template with a PHP template partial to display the block contents. Inside the template is some HTML (section with a figure and an a inside it). When the block is called and the template generates the HTML, it's exactly as I author it, but when displayed on the front end, the a gets wrapped in a p tag, and a couple of br elements are added …
Category: Web

remove_filter( 'the_content', 'wpautop' ); is not working for me

I use Tinymce Advanced plugin. I would like to remove p tag by adding this code remove_filter( 'the_content', 'wpautop' ); to my functions.php. However, it does't work. When I press ENTER, it still inserts double line, not single line. The p character still displays at the bottom left of the textarea.
Category: Web

Understanding automatic text formatting in the Wordpress editor

Why does the text editor remove paragraphs and line breaks? Surely maintaining basic formatting such as paragraphs or line breaks is a basic requirement in all CMS systems. It's hard to believe that WordPress has remained the most popular content management system on the market when it's not even able to maintain basic text formatting. I've searched numerous forums - all of which recommend the TinyMCE Advanced plugin or manipulating the wpautop() function - but nowhere is there a clear …
Category: Web

Wordpress blockquote removes `<br>` tag

So I have a quote in my page template and I would like to give the user the opportunity to add line breaks whenever they desire to do so. I wanted the blockquote to have an extra &lt;p&gt; tag inside the &lt;blockquote&gt; tag so I could style it better. The problem I'm having now is that the &lt;br /&gt; tags are being removed. While using the wpautop() function they should stay. Here is what I did: $matched = preg_match("~(?&lt;=&lt;blockquote&gt;)([\s\S]+?)(?=&lt;/blockquote&gt;)~", wpautop($child-&gt;post_content), …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.