admin管理员组

文章数量:1201415

Trying to start writing some plugins, however everytime i use the shortcode that calls my function plugin, the function ends up above the header on that page, instead of right where i placed the shortcode.

Here is an example of what i used:

Trying to start writing some plugins, however everytime i use the shortcode that calls my function plugin, the function ends up above the header on that page, instead of right where i placed the shortcode.

Here is an example of what i used:

Share Improve this question asked Apr 12, 2022 at 22:51 Ironside GamingIronside Gaming 1 1
  • Please don't paste in a screenshot of your code; paste in the actual code, which will be more accessible and also much easier for us to diagnose. – Pat J Commented Apr 12, 2022 at 23:45
Add a comment  | 

1 Answer 1

Reset to default 0

Shortcodes should return their content, never echo it.

From the add_shortcode() docs:

Note that the function called by the shortcode should never produce an output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results.

But the functions you appear to be using—the_title() and the_date()—both echo their output by default. Consider using get_the_title() and get_the_date() instead. You'll need to refactor some of the rest of your code too, but this should be a good starting point.

本文标签: My plugins are ending up above the header