I am using Shortcode exec php plugin and putting PHP code in a post via Wordpress Posts panel.

add_action( 'wp_loaded', 'echoFunction');

function echoFunction(){
    echo "someText";

Why doesn't this work? and how do I make it work?

1 Answer 1


wp_loaded is called long, long before the post content is fetched. Put that code into a plugin.

Also, you shouldn't echo anything that early. The HTTP headers aren't sent yet on wp_loaded, so you will get the Headers already sent error, and your user authentication will not work: you cannot log in anymore.

  • You mean I should make my own plugin, yes? Ty May 17, 2015 at 17:37
  • @user2879175 Yes, exactly. :) I have added a link to my answer that leads to a post explaining how to do that.
    – fuxia
    May 17, 2015 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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