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 would like to create shortcodes, some tutorials write about to use add_action

add_action( 'init', 'register_shortcodes');

but I read tutorials where the author didn't use it, only put

add_shortcode('recent-posts', 'recent_posts_function');

to functions.php. Which is the best method, and why to use add_action?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

If you take a look at the Codex page about add_shortcode() you won't see anything about the need of an add_action() before you can use add_shortcode().

So, you can just put your add_shortcode() directly into your functions.php. This is what I do too.

See this article - WordPress Shortcodes: A Complete Guide about the use of shortcodes and best practices.

share|improve this answer
    
Thank you very much! –  Rolnin Mar 13 '13 at 8:43
    
You have actuaclly linked to an article saying you should wrap in an action. –  raam86 Sep 1 '13 at 13:39
add comment

Your Answer

 
discard

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.