0

I'm developing a plugin that given a shortcode with attributes will scan a json file and return the appropriate data etc.

Given code like this:

<!-- wp:paragraph -->
<p>[environ data="day_max" format="long"]</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>[environ data="day_min"]</p>
<!-- /wp:paragraph -->

Data is being returned like

9.82°C at 12:49:59 AM 9.82°C

without the paragraphs and bunched together. If I add any leading text the problem vanishes (see below). If I place short codes within table cells it vanishes. The issue only presents itself if the short code is alone in a paragraph.

<!-- wp:paragraph -->
<p>Test [environ data="day_max" format="long"]</p>
<!-- /wp:paragraph -->

returns

<p>Test 9.82°C at 12:49:59 AM</p>

I've looked at Remove empty p-Tags in Shortcode content before non p-Tags and similar posts but they don't seem to address this issue.

My code is a add_shortcode('environ', array(&$byteenviron ,'byteenviron_display_handler')); function call to byteenviron_display_handler which processes the attributes and returns a string.

2
  • I don't currently have an answer to what's asked in the question, but why not just add the paragraph in your shortcode handler function? I.e. Add it conditionally - if there should be something non-empty to return, then include the paragraph tags; else, then return an empty string. So for example, return $output ? "<p>$output</p>" : '';.
    – Sally CJ
    Commented Apr 13, 2022 at 4:05
  • .. and then use the Shortcode block instead to add your shortcode.
    – Sally CJ
    Commented Apr 13, 2022 at 4:14

0

Your Answer

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

Browse other questions tagged or ask your own question.