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 new to Wordpress and trying to take advantage of the framework as much as possible. On the front end, I want a centralized message area to display error, success, and general notices similar to how they're handled via admin_notices on the back end. I'm not seeing a similar hook for the front end.

I guess I'm asking which action should I be hooking into on the front end to mimic admin_notices?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

There is no such action in the front end (in a theme) by default. Simply use a custom action like

do_action( 'theme_notices' );

and hook into this one.

share|improve this answer
1  
Awesome. I'll try that. Thank you! –  mjleitch Dec 5 '12 at 13:38
    
Looking into this a bit further... If I'm wanting to make my plugin theme-independent, would it make more sense to set a global variable for the messages rather than using do_action? This way themes could output the messages from any location. If I understand correctly, do_action would be placed in a specific spot in the theme files. Ideally, I'd like to have the notices output during get_header action by default if the theme has no explicit integration with the plugin, but give themes the option to output in a different spot if desired. Does that make sense? –  mjleitch Dec 5 '12 at 16:32
    
There's exactly no such hook anywhere in a theme by default. Using a global would just pollute the namespace. And adding such a custom hook has the same effect (and can be used anywhere and multiple times) plus it doesn't throw around errors when your plugin isn't active and the global isn't set. –  kaiser Dec 5 '12 at 16:49
    
Understood. Thanks. –  mjleitch Dec 6 '12 at 0:02

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.