0

I'm in route of creating my first plugin and ran across some tutorials that make use of wp_head() as a action hook for loading meta data. But that fired an idea in my head to see if Wordpress also provides hooks for areas "inside" the body element.

For example, within new my plugin, my function should prepend or append html content within the <header> element, by the help of a hook.

Is setting up a hook for something like this, already available through WP? If not, how do I created a custom hook to carry out this action?

Thanks for any tips!

  • You can edit body class using a filter but not the body. There are a couple themes out there that use do_action('after_body_open_tag') but this is not used by most themes. – James Apr 13 '18 at 0:14
  • Thanks. so what you are really saying is that if I am looking for an OOTB solution, it's up to the theme to provide that hook. I get it. But if I am starting fresh in a starter theme, what is the wordpress way of creating something like this from scratch? I don't mind creating custom hooks for a custom theme...i just don't know how. – klewis Apr 13 '18 at 0:18
  • You will want to look into do_action(). developer.wordpress.org/reference/functions/do_action – James Apr 13 '18 at 0:22
  • 1
    This also helps - developer.wordpress.org/plugins/hooks/custom-hooks – klewis Apr 13 '18 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.