Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

wordpress

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.

like image 287
Milos Avatar asked Mar 02 '26 23:03

Milos


1 Answers

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

So, instead of doing

'echo "something" '

Do

' return "something" '

like image 146
user1049961 Avatar answered Mar 04 '26 12:03

user1049961



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!