In my theme I have add_theme_support('custom-header') and add_image_size('hero', 435, 290, true).
When I output my custom header in a template file I would like to show the 'hero' version (435x290) of my custom header, not the original, uploaded image.
Please can somebody help me write a function to accomplish the above.
Many thanks.
Solution - 1
The code below is not tested... Have a backup of your own and test its working...
attachment_id), 'hero', false);
if(isset($hero_src[0])) {
?>
Solution - 2
Try this:
ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'hero' ); ?>
It will check if the post has a thumbnail, Then if it does, will show the image.
Solution - 3
try this :
ID) && ($image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(
$header_image_width,
$header_image_width
))) && $image[1] >= $header_image_width):
echo get_the_post_thumbnail($post->ID, 'hero');
else:
if (function_exists('get_custom_header'))
{
$header_image_width = get_custom_header()->width;
$header_image_height = get_custom_header()->height;
}
else
{
$header_image_width = HEADER_IMAGE_WIDTH;
$header_image_height = HEADER_IMAGE_HEIGHT;
} ?>
don't forget to regenerate thumbnails : http://wordpress.org/extend/plugins/regenerate-thumbnails/ after add/remove custom image size :)
hope this help, :)
Solution - 4
Put this in your functions.php
add_theme_support( 'post-thumbnails' );
add_image_size( 'hero', 200, 200, true ); // Set hero post thumbnail class, true param means crop
then in your template something like
'hero')); ?>
Or for attachment you can do the following which is what i use
and to retrieve the attachment

Forget the above i misread the question. Here are some references.
Custom Header
This feature enables Custom_Headers support for a theme as of Version 3.4.
add_theme_support( 'custom-header' );
Note that you can add default arguments using:
$defaults = array(
'default-image' => '',
'random-default' => false,
'width' => 0,
'height' => 0,
'flex-height' => false,
'flex-width' => false,
'default-text-color' => '',
'header-text' => true,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
add_theme_support( 'custom-header', $defaults );
Source: http://codex.wordpress.org/Custom_Headers
Solution - 5
Hi designbuildtest,
Please test this code, from Twenty Eleven's header.php, changed to use 'hero' size.
// Check to see if the header image has been removed
$header_image = get_header_image();
if ( $header_image ) :
$header_image_width = get_custom_header()->width;
?>
ID ) &&
( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) ) ) &&
$image[1] >= $header_image_width ) :
// Houston, we have a new header image!
echo get_the_post_thumbnail( $post->ID, 'hero' );
else : ?>
Regards,
Gabriel
|