How to Remove Unwanted

Tags from ACF WYSIWYG Fields in WordPress

How to Remove Unwanted <p> Tags from ACF WYSIWYG Fields in WordPress

In this post, we will show you how to delete additional <p> tags from the WYSIWYG field. When working with Advanced Customs Field (ACF), especially with WYSIWYG editors, you can see that the WordPress automatically is unwanted <p> (paragraph tag around your content. This becomes a problem when you are working with SVG, custom HTML, or strictly controlled layout structure.


How to Remove Unwanted p Tags from ACF WYSIWYG Fields in WordPress


The Solution: Use preg_replace() to Strip Tags

<?php elseif ($media_image_type == 'svg' && $variable_name): ?>
  <?php echo preg_replace('/^<p>|<\/p>$/', '', $svg_content); ?>
<?php endif; ?>

Explanation

If the content starts with <p> Or if the end is a closing </ p>. It removes those tags, causing your real content.

Newest
Previous
Next Post »

Please do not entering spam link in the comment box ConversionConversion EmoticonEmoticon