1

I have created a custom shortcode [colored-list] to simply print an HTML code template. The reason to build this shortcode is because I am using PHP loop in it to print the list of text in different color sets based on the item count. So e.g. first text will be red, second blue, third yellow, fourth again red,...blue, yellow. So this is how I have built a color cycle for every text.

I have created lot more shortcodes for different purposes but above one is just for example.

Now what I am doing is, I have created a WYSIWYG editor using Advanced Custom Field plugin to add some more content. And I am using this shortcode in it. But every time I echo it on frontend, it prints with P tags added to so many places.

I have tried so many fixes like removing wpautop filter, applying "the_content" filter etc. But none of them helped.

4
  • Have you tried viewing the wysiwyg editor in Text mode and deleting line breaks? That may remove some of them. One other option might be to make the ACF field a text field instead of wysiwyg editor. You can include HTML in an ACF text field, though if you have non-techie users this may be a pain for them. If neither solution works, I'd suggest contacting ACF directly. One similar thread: support.advancedcustomfields.com/forums/topic/…
    – WebElaine
    Commented May 19, 2017 at 15:02
  • Yes I have checked it in text mode. Infact I used same content in Standard content editor that shows data on frontend using the_content() method and there it works perfectly. I have already contacted ACF support guys and they are telling me to remove wpautop filter. But that will make the content without P tags (even the needed one) which is again not a good result. Commented May 19, 2017 at 15:12
  • Maybe use a second shortcode? If the repeating content inside [colored-list] is similar you could add the correct <p> tags that way. Then just make sure there are no line breaks between the nested shortcodes.
    – WebElaine
    Commented May 19, 2017 at 15:14
  • colored-list is just an example shortcode I have used for the query, actually there are lot more shortcodes I have built which are being integrated with ACF so it's better to have some solid solution and not temporary. Commented May 19, 2017 at 15:17

1 Answer 1

1

I got it fixed with below code :)

$section_content = get_sub_field('section_content', false, false); 
$section_content = apply_filters('the_content', $section_content);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.