0

I recently created a custom shortcode that can have as many as 35 parameters in it. It's a complicated item, so part of the reason I created the shortcode was so I could see the parameters easily if I typed them out in a grid like this:

 [shortcode paraA1='123' paraB1='321'
            paraA2='234' paraB2='432'
            paraA3='345' paraB3='543' ]

It works just fine, except if I type them out like above in succession, it will completely ignore the top ones and only parse the bottom one. So this:

 [shortcode paraA1='123' paraB1='321'
            paraA2='234' paraB2='432'
            paraA3='345' paraB3='543' ]
 [shortcode paraA1='456' paraB1='654'
            paraA2='567' paraB2='765'
            paraA3='678' paraB3='876' ]
 [shortcode paraA1='789' paraB1='987'
            paraA2='890' paraB2='098'
            paraA3='901' paraB3='109' ]

will parse as if I had only typed this:

 [shortcode paraA1='789' paraB1='987'
            paraA2='890' paraB2='098'
            paraA3='901' paraB3='109' ]

The source code shows as if the first two shortcodes do not even exist. It will also ignore any code that is between them.

However, if I type them out without the line breaks (i.e. all inline) then it will work without any issues. For example:

 [shortcode paraA1='123' paraB1='321' paraA2='234' paraB2='432' paraA3='345' paraB3='543' ]
 [shortcode paraA1='456' paraB1='654' paraA2='567' paraB2='765' paraA3='678' paraB3='876' ]
 [shortcode paraA1='789' paraB1='987' paraA2='890' paraB2='098' paraA3='901' paraB3='109' ]

will work just fine.

I have multiple items running that kill wpautop, so I'm pretty sure it's not that. How can I fix this problem so that shortcodes will run correctly with line breaks in them?

I always work in the text editor only, and never the visual editor.

  • Can you provide a little context as to why you need such complex shortcodes that linebreaks are necessary? What prevents them from simply being on a single line? – Tom J Nowell Oct 13 '16 at 23:36
  • @TomJNowell Nothing prevents them from being inline. It's just in the way I intend to use the shortcode, there will be a series of tens of them, most with at least 10 parameters each. It's basically a data table, so I would like to be able to look at it like that when I'm editing. It helps me keep track of everything. As to why they are complicated on their own, it's way more involved then I think you'd find helpful to answer the question. – 38365 Oct 13 '16 at 23:40
  • Is there an escape character that you can use in shortcodes? Probably not? wordpress.stackexchange.com/questions/33960/… – 38365 Oct 13 '16 at 23:44
  • This likely has more to do with parsing shortcodes in core, but if the goal of this is to make a super verbose shortcode for creating tables, then there are plugins that give visual UIs for that, and of course, why not have a table shortcode with nested shortcodes instead of hundreds of parameters? Keep in mind that any answer should answer your question, if you have another question you can ask that in a new question – Tom J Nowell Oct 14 '16 at 0:37
  • 1
    hmmm, if the shortcode just lists links with some custom logic, then why do they need so many parameters? I get the feeling a huge chunk of context is missing here – Tom J Nowell Oct 14 '16 at 0:46
0

There are two workaround options I've found:

Workaround 1: You can use an indiscriminate number of non-breaking spaces where you would like a line break.

So to imitate this:

 [shortcode paraA1='789' paraB1='987'
            paraA2='890' paraB2='098'
            paraA3='901' paraB3='109' ]

You can enter:

  [shortcode paraA1='789' paraB1='987'                                                paraA2='890' paraB2='098'                                                paraA3='901' paraB3='109' ]

The Wordpress text editor will wrap the text, but not the spaces, so the result will look exactly like this:

[shortcode paraA1='789' paraB1='987'
paraA2='890' paraB2='098'
paraA3='901' paraB3='109' ]

but each line will have spaces at the end, which will be selected if you need to copy and paste for some reason. This will run any number of successive short codes without error.

Workaround 2: Put content between each shortcode, such as a non-breaking space  .

You can do this:

[shortcode paraA1='123' paraB1='321'
           paraA2='234' paraB2='432'
           paraA3='345' paraB3='543' ]  
[shortcode paraA1='456' paraB1='654'
           paraA2='567' paraB2='765'
           paraA3='678' paraB3='876' ]  
[shortcode paraA1='789' paraB1='987'
           paraA2='890' paraB2='098'
           paraA3='901' paraB3='109' ]  

and it will parse all the shortcodes correctly. This technically is not "successive shortcodes", but in most instances   will add no content display differences.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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