Community Forums › Forums › Archived Forums › Design Tips and Tricks › Conditionally Relocate Entry Header: Best Method and Hook(s)?
Tagged: conditional, hook, hooks, move, php, relocate, reposition
- This topic has 3 replies, 2 voices, and was last updated 10 years, 4 months ago by
Tonya.
-
AuthorPosts
-
October 8, 2014 at 12:06 pm #127128
Joe Thomas
MemberIn my current custom child theme, I want to relocate any page's entry header into a custom hook,
joe_hero_wrap
, only if there is a featured image set for that page. I've figured two ways of doing it (and they both work), but I want to ensure I do it the proper way, conforming to WordPress and Genesis best practices. Here are the two successful methods I've used (code is inpage.php
).Method 1: One conditional hooked to
genesis_meta
//* Relocate entry header conditionally (if featured image exists) add_action( 'genesis_meta', 'joe_relocate_entry_header' ); function joe_relocate_entry_header() { if ( has_post_thumbnail() ) { remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); add_action( 'joe_hero_wrap', 'genesis_entry_header_markup_open', 5 ); add_action( 'joe_hero_wrap', 'genesis_do_post_title' ); add_action( 'joe_hero_wrap', 'genesis_post_info', 12 ); add_action( 'joe_hero_wrap', 'genesis_entry_header_markup_close', 15 ); } }
Method 2: Two conditionals hooked to
genesis_entry_header
andjoe_hero_wrap
(with high priority)//* Reposition entry header conditionally (if featured image exists) /* Remove it! */ add_action( 'genesis_entry_header', 'joe_remove_entry_header', 0 ); function joe_remove_entry_header() { if ( has_post_thumbnail() ) { remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 ); remove_action( 'genesis_entry_header', 'genesis_do_post_title' ); remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 ); } } /* Add it! */ add_action( 'joe_hero_wrap', 'joe_add_entry_header', 0 ); function joe_add_entry_header() { if ( has_post_thumbnail() ) { add_action( 'joe_hero_wrap', 'genesis_entry_header_markup_open', 5 ); add_action( 'joe_hero_wrap', 'genesis_do_post_title' ); add_action( 'joe_hero_wrap', 'genesis_post_info', 12 ); add_action( 'joe_hero_wrap', 'genesis_entry_header_markup_close', 15 ); } }
So, which one of the above is best practice? Or, am I completely out to lunch? Or, is there another hook I should use instead of
genesis_meta
for the Method 1?
Owner/Web Developer at LocalBoost.
October 8, 2014 at 12:52 pm #127139Tonya
MemberHi Joe,
Honestly, either way works. However, I typically like to hook in early by using genesis_meta and handling all the tasks there.
Cheers,
Tonya
Software & Electrical Engineer and Programming Teacher · I’m on a mission to help developers be more awesome.
Find Me: KnowTheCode.io | @hellofromTonya | Profitable WordPress Developer BootcampOctober 8, 2014 at 1:33 pm #127148Joe Thomas
MemberThanks, Tonya. Using
genesis_meta
is more concise, too, so that's nice.
Owner/Web Developer at LocalBoost.
October 8, 2014 at 1:44 pm #127149Tonya
MemberYou're welcome. I agree 🙂
Software & Electrical Engineer and Programming Teacher · I’m on a mission to help developers be more awesome.
Find Me: KnowTheCode.io | @hellofromTonya | Profitable WordPress Developer Bootcamp -
AuthorPosts
- The topic ‘Conditionally Relocate Entry Header: Best Method and Hook(s)?’ is closed to new replies.