When cropping a header image, retain meta data (i.e. name, description, etc.) from original image?

Here’s one idea, that might need further testing: /** * Cropped header image with the same description/caption as the original image */ add_filter( ‘wp_create_file_in_uploads’, function( $cropped, $attachment_id ) { add_filter( ‘wp_insert_attachment_data’, function( $data ) use ( $attachment_id) { if( doing_action( ‘wp_ajax_custom-header-crop’ ) && is_array( $data ) ) { // Copy the original description to the … Read more

How to get the custom header image’s alt text?

/** * Get custom header’s alt data. * * @link http://wordpress.stackexchange.com/q/151850/1685 * * @return string */ function wpse_151850_get_header_image_alt() { $attachment_id = 0; if ( is_random_header_image() && $header_url = get_header_image() ) { // For a random header, we have to search for a match against all headers. foreach ( get_uploaded_header_images() as $header ) { if ( … Read more

How can i get the name parameter defined in get_header?

There is an action get_header that you can use. In your theme’s functions.php, register a callback for that action: add_action( ‘get_header’, function( $name ) { add_filter( ‘current_header’, function() use ( $name ) { // always return the same type, unlike WP return (string) $name; }); }); You could also write a little helper class that … Read more