Code in head of Genesis WP for particular page

Occasionally we all need to place some piece of code in header.php but to show up just on some page, not on all of them. Not needed to be custom page, but maybe you need it just on home page or just to one category, etc.
In usual themes that’s easy. You make page-2.php if 2 is ID of that page, and then you call not header but header(home) for instance, and make new header-home.php with that code.

But if you are using Genesis theme, this can be difficult. So in that case, easiest way would be to copy header.php from genesis theme, and paste it to child theme. Then open that file and edit. Before closing header tag, just add this:

[codesyntax lang=”php”]

<?php
if(is_page('2')){
echo '
<script type="text/javascript">
your code
</script>
';
}
?>

[/codesyntax]

In this example, ID of desired page is 2, so you should change number in is_page(‘2’) with your page ID.
Also, example is for javascript, but you can add anything you need.

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

22 − 14 =