Forums

Handling shortcodes which fall outside paragraph tags (3 posts)

  1. albedoa
    Member
    Posted 1 year ago #

    If you have a simple shortcode function such as this:

    function short ( $atts, $content ) {
    return $content;
    }

    Is there a simple way to have it behave as the rest of my post content does when wpautop is on? For instance, typing this in the html editor:

    Here is a paragraph. Tags are not necessary, as they are applied automatically.
    
    [short]Code[/short]
    
    [short]Code[/short] and some other content.
    
    A [short]code[/short] in the middle of a sentence.

    Would produce:

    <p>Here is a paragraph. Tags are not necessary, as they are applied automatically.</p>
    <p>Code</p>
    <p>Code and some other content.</p>
    <p>A code in the middle of a sentence.</p>
  2. albedoa
    Member
    Posted 1 year ago #

    Strange, I just realized that the desired output is indeed produced except for when the shortcode is the very first word of a post. The output for:

    [short]Code[/short] and some other content.

    Looks like this:

    Code and some other content.</p>

    With no leading paragraph tag. This is a much lesser problem, but still a problem.

    So does anyone know how to force the leading paragraph tag in case I forget and lead my post with a shortcode? Thanks!

  3. albedoa
    Member
    Posted 1 year ago #

    Nevermind. The reason that it seemed to work is because it is working inconsistently. I cannot figure out how it determines whether or not to apply <p> tags.

Topic Closed

This topic has been closed to new replies.

About this Topic