Hi, thanks for sharing your work. There’s an issue with the shortcode function – it’s a classic mistake and easy to fix.
Shortcodes are executed/printed before the rest of the page contents. That means if the page with the [sitemap] shortcode contains any text, it will only be displayed after the sitemap output regardless of where the shortcode is placed. That’s a problem, because I wanted to put a title above the sitemap output!
The solution is to load all of the shortcode output into a variable and return the contents instead of echoing directly in the shortcode. This way, the contents will appear in the desired location and text can be wrapped around the output.
I’ve reformatted the add_shortcode() function to do precisely this. I would highly recommend switching over to this format for your future updates!
Best of luck 🙂
- The topic ‘Shortcode output appears before other page text’ is closed to new replies.