Support » Fixing WordPress » How can I specify a line break in a shortcode expansion?

  • I have a shortcode to help create a table with each cell containing a <figure> with a <figcaption>. It is invoked with:

    [mycode photo=’photo URL’ cap=’my caption text here’]

    Sometimes, my caption text is too long to fit on one line in the cell. I would like to specify where the linebreak should be within the caption text, rather than letting the browser choose where to break.

    But I can’t do this: [mycode photo=’photo URL’ cap=’my caption<br />text here’]

    That causes the caption to display as “my caption<br />text here”.

    Nor can I do this: [mycode photo=’photo URL’ cap=’my caption
    text here’]

    That gets converted to this HTML:

    <figcaption>
    <p></p>
    my caption
    <p>text here</p>
    </figcaption>

    I might attempt to parse my ‘cap’ parameter in my shortcode PHP code, but I don’t think I yet understand when various other editors and parsers tinker with the parameters.

    I might add a third parameter to my shortcode so that the caption’s second line is passed separately, but that seems like a kludge.

    I would appreciate other suggestions.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Priyanka Behera

    (@priyankabehera155)

    Hi @plaidflannel

    I have tried your code in WordPress twentynineteen theme and it is working as expected adding the <br/>

    add this shortcode: [mycode photo=’photo URL’ cap=’my caption<br />text here’]

    You can also check the link: http://9588b561.ngrok.io/hello-world/

    Can you please confirm your code in another theme.

    Thanks

    You said, “add this shortcode: [mycode photo=’photo URL’ cap=’my caption<br />text here’]”

    That is exactly what I tried first (see paragraphs 4 and 5 of my original post).

    The link http://9588b561.ngrok.io/hello-world/ gets me to a page containing only:

    Tunnel 9588b561.ngrok.io not found

    You said, “Can you please confirm your code in another theme.”

    My code is deep in a child theme. I’m not sure I can test it easily in another theme without building at least a little bit of a new child theme. Or is it as simple as adding a copy of my shortcodes.php file to that other theme?

    Priyanka Behera

    (@priyankabehera155)

    hey @plaidflannel ,

    Check the screenshot https://nimb.ws/xCKLHF.

    My code is deep in a child theme. I’m not sure I can test it easily in another theme without building at least a little bit of a new child theme. Or is it as simple as adding a copy of my shortcodes.php file to that other theme?

    If there is any default WordPress theme, like twentynineteen or tweentyeighteen. Then copy you

    add_shortcode('mycode', 'your-function-link-to-shortcode');
    function your-function-link-to-shortcode(){
     code inside it
    }

    to the default WordPress functions.php and paste it at the end.

    Then change the theme from the admin panel.

    Next, create a post and check the shortcode.

    Let me know if this is helpful or not.

    Thanks

    Thanks.

    It is bedtime in my timezone right now, so I’ll be a day or so getting back to this.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    *Reads*

    Moved to Fixing WordPress, this is not a Developing with WordPress topic.

    Side note: @priyankabehera155 Please do not use that site anymore. The ngrok one. Like URL shortners those sort of links are discouraged as it is designed to intentionally hide where people are going to and that’s not cool.

    Priyanka Behera

    (@priyankabehera155)

    Hi @jdembowski

    Thank you for informing about ngrok link. I will not be going to use it in the support anymore. Actually, I am using the Flywheel live link which provides the link. But sure as said I will not use it anymore.

    I have tried my shortcode with two other themes: my parent theme (Zita) and Clearex. I get the same results as detailed in my original post.

    The kludge mentioned in my original post works. Fortunately, my captions are such that it is usually easy to know when a line break will be needed. So, for know, that’s what I am doing.

    Question to moderator: does having a workaround count as having my question resolved? Or should it remain open in the hope that the cause of the problem will ultimately be identified?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How can I specify a line break in a shortcode expansion?’ is closed to new replies.