I would like to insert a full-width DIV at the topmost location in the site I'm building. The project is in overtime. All the other work is done, but I have been asked to add a small logo and a single link on top. This would be on all pages, so it's a modification to the header. I've looked at several plugins, but they seem to be creating a "notification bar" by positioning and z-index. The theme we're using is Velux, a child of Primer.

  • I don't see this as 'off-topic'. The OP is looking for a way to insert content just after the body tag. To do so, he would have to modify header.php, which is a WP file, and would be the process no matter which theme he is using. So it seems to me to be a WP developer question: "how do I modify a theme to do something?". The 'canned reason' doesn't seem to apply here. I will admit that I am still learning the 'rules' of this place, so a justification of the 'hold' would be of interest to me. – Rick Hellewell Aug 23 '17 at 23:17

As I can see in wp-primer-theme sources: there are do_action( 'primer_body' ); on the top of content and do_action( 'primer_before_header' ); just below.

You can update your child theme functions.php with your own action

add_action('primer_before_header', function() {
  echo '<div class="logo"></div>';
| improve this answer | |
  • Although I haven't yet tested this idea, I believe it will work, and it takes place in one of the PHP files not considered to be core WordPress. PS - Yes, I have read the article at wpmudev.org saying that functions.php is often being used unwisely. – Luke 5 Dev Aug 24 '17 at 13:56

Take a look at this question, and the first answer: Insert HTML just after <body> tag

You will have to modify header.php in the theme, since there aren't (normally, although perhaps in your theme) any hooks/filters available to output directly after the <body> tag.

If not your own maintained theme, then a Child Theme is best, as you don't want to have your changes overwritten on a theme update.

| improve this answer | |
  • You are right about using a child theme. But this theme is already a child to Primer. I've been told conflicting things about the "grandchild theme" idea in WordPress. First it was out of the question, then it was maybe in the works, now my research on the matter does not result in a clear answer. I may be wandering off topic. – Luke 5 Dev Aug 24 '17 at 13:47
  • Quick research shows that grandchild themes probably won't work, and the 'core' peoples don't recommend it's use. You might look at the Child Theme's header.php file and see if there are any hooks in there you can use. – Rick Hellewell Aug 24 '17 at 17:21

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