How To Add Code To A Genesis page.php File

This free tutorial for beginners provides the code you can use/modify to add/execute your code in a genesis page.php file. Many 3rd party plugins will instruct you to add a template tag or function call to your themes page.php file.

In Genesis, you’ll need to use the following code in your functions file to execute your plugins function call in your themes page template.

add_action( 'genesis_entry_header', 'your_function', 5 );
function your_function() {

if ( ! is_singular('page'))
    return;

// Your code 
}

The above code enables you to execute your code on single pages only.

Swap out // Your code with the code you want to execute on single pages and add the code to the end of your child themes functions file.

You can change the 1st line of the code which includes the genesis_entry_header hook to any other location.

Example: To execute your code after the content of all single pages, change the hook from genesis_entry_header to genesis_entry_footer.

Here’s what the 1st line of the above code will look like after changing the hook:

add_action( 'genesis_entry_footer', 'your_function' );

Here’s a visual guide showing the different positions different hooks execute in a Genesis template.

You can modify the is_singular('page') conditional tag in the code to include or exclude which pages the code executes on.

Other Options

You can create a basic page template file in your child themes root directory like this:

And name the file according to the WordPress Template Hierarchy.

Here are the file name options:

  1. Create a custom page template file – The page template assigned to the page under the Page Attributes meta box on the Page Edit screen.
  2. page-{slug}.php – If the page slug is contact, WordPress will load the file named page-contact.php.
  3. page-{id}.php – If the page ID is page-id-10452, WordPress will load the file named page-10452.php.
  4. page.php
  5. singular.php
  6. index.php

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.