Skip to content

Instantly share code, notes, and snippets.

@bpmore
Last active April 15, 2019 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpmore/2e53ad98df91a2436fe2cf3bb6f07fc8 to your computer and use it in GitHub Desktop.
Save bpmore/2e53ad98df91a2436fe2cf3bb6f07fc8 to your computer and use it in GitHub Desktop.
Header with image or header with image and page title -- work in progress -- for Genesis WordPress.
<?php
// This adds logo to header, adds page title if using special page template, and...
//
// Here goes the logo in Header
//
add_action( 'genesis_header', 'ursidae_site_image', 5 );
function ursidae_site_image() {
if ( is_page_template( array( 'page_special.php', 'page_other_special.php' ) ) ) {
// Do the thing below if either of the above templates are being used
//First we add the logo
$header_image = '<img src="' . get_stylesheet_directory_uri() .'/images/logo.png" alt="University of Arkansas for Medical Sciences Logo" />';
printf( '<div class="site-image"><a href="http://uams.edu/">%s</a> <span class="pipe">|</span></div>', $header_image );
// Then start the magic to add page title in header area
function get_post_parent( $post=null )
{
//initializing
global $wp_the_query;
if (!$post)
$post = $wp_the_query->post;
//reasons to return false
if (!is_object($post) || is_wp_error($post)) return false;
if (!$post->post_parent) return false;
//load and return the parent
$parent = get_post($post->post_parent);
return $parent;
}
/**
* Function is responsible for returning the parent page if it exists or returning the current page if the parent does not exist.
* Need to figure out how to make the child pages write the parent page title. This needs to happen here!
* @return object
*/
function get_highlighted_excerpt()
{
if (!$post = get_post_parent())
{
global $post;
}
return $post;
}
// these next lines of code should be placed in the location that you want to output the parent title and excerpt
// if the parent page exists
if ($parent = get_highlighted_excerpt())
{
echo "<div class='post-title'>{$parent->post_title}</div>";
}
}
else {
//If no special page then drop in the logo and be done
$header_image = '<img src="' . get_stylesheet_directory_uri() .'/images/logo.png" alt="University of Arkansas for Medical Sciences Logo" />';
printf( '<div class="site-image"><a href="http://uams.edu/">%s</a> <span class="pipe">|</span></div>', $header_image );
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment