Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm developing a simple plugin for letting a user insert a post from the frontend.

I have a shortcode [add-post] which a user can put on any page, say, for eg. My Wall Page

Now on My Wall Page a simple form comes up which has a title field, a content field and a category select field so that user can choose which category to put his post into.

I'm not sure as what the action should be?

function my_function(){
  <form>...My form for inserting a new post goes here...</form>

add_action('????', 'my_fucntion');

What should the hook be? I tried 'init', 'widgets_init' but to no avail. If i don't add any action or even if I do add 'init' or 'widgets_init', it displays my form 3 times; two times at the top and one time in place of the shortcode (i.e, it replaces my shortcode)

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You don't need to hook into an action for a shortcode - adding the shortcode using add_shortcode() will make it run when you call the_content(). That said, your function for your shortcode needs to return your output, not just echo it outright. Otherwise you will find that your form will appear much earlier than you expect it to.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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