问题
Am woking on an error plugin. I want to generate some error or success msgs when header loads in WordPress blog site.
like as:
if(is header load)
{
//run a action hook here
//print success or error msgs through hook function
}
suggest a hook action to display msgs when header load.
回答1:
Below code might help. You can put this code in the functions.php in your theme folder.
function load_me_on_header()
{
// do something here ... like show error message.
}
add_action('wp_head','load_me_on_header');
回答2:
You can also use the add_filter() function the same way. Filters are more suiteble when content processing is invold.
来源:https://stackoverflow.com/questions/10315647/how-to-run-a-hook-action-when-header-load-in-wordpress-blog