Search code examples
phphtmlwordpressgenesis

Add h2 within .entry-content under h1 genesis


I am trying to add an h2 under the h1 within the .entry-content div on the genesis framework.

I would like the code to output the following:

<header class="entry-header">
   <h1 itemprop="headline" class="entry-title">Page Header Title</h1>
   <h2>Page Sub Header Title</h2> 
</header>

I believe I need an action hook of some kind but I'm not 100% sure to begin.

My next thought is how would I add the h2 content for each page? As each page will need to have a different h2. Will I need to create a custom field or call the h2's conditionally onto each page?

Any thoughts on this?

Thanks, William


Solution

  • One way to achieve this is to use the genesis_entry_header action. So, you could add the following to your functions.php to get a sub title

    add_action('genesis_entry_header', 'handle_event_sub_title');
    function handle_event_sub_title(){
        global $post;
        echo get_post_meta($post->ID,'sub_title')?sprintf('<h2>%s</h2>',get_post_meta($post->ID,'sub_title')):'';
    }