Milos Milos -4 years ago 109
PHP Question

Wordpress multiple shortcodes on same page doesn't keep element ordering

I'm writing a plugin that creates shortcodes. Even though the shortcodes parse as they should, I have a problem when using multiple shortcodes on the same page. So, if I do it like this in post editor:

[foobar]
<p>Lorem ipsum text</p>
[foobar]
<p>Some other text</p>
[foobar]


the HTML output is:

<div class="foobar">Foobar</div>
<div class="foobar">Foobar</div>
<div class="foobar">Foobar</div>
<p>Lorem ipsum text</p>
<p>Some other text</p>


So, it places all the shortcodes one after another, and then displays the rest of the text on page. Instead, I'd like to have that as I wrote it in post editor.

Answer Source

Your problem is probably that you are echo'ing the values, instead of returning them.

So, instead of doing

'echo "something" '

Do

' return "something" '

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download