Last active
August 29, 2015 14:15
-
-
Save devinsays/4669f5feba038ea0f40a to your computer and use it in GitHub Desktop.
Display Featured Image Meta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Adds a checkbox to the featured image metabox. | |
* | |
* @param string $content | |
*/ | |
function prefix_featured_image_meta( $content ) { | |
global $post; | |
$text = __( 'Don\'t display image in post.', 'prefix' ); | |
$id = 'hide_featured_image'; | |
$value = esc_attr( get_post_meta( $post->ID, $id, true ) ); | |
$label = '<label for="' . $id . '" class="selectit"><input name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $value . ' "'. checked( $value, 1, false) .'> ' . $text .'</label>'; | |
return $content .= $label; | |
} | |
add_filter( 'admin_post_thumbnail_html', 'prefix_featured_image_meta' ); | |
/** | |
* Save featured image meta data when saved | |
* | |
* @param int $post_id The ID of the post. | |
* @param post $post the post. | |
*/ | |
function prefix_save_featured_image_meta( $post_id, $post, $update ) { | |
$value = 0; | |
if ( isset( $_REQUEST['hide_featured_image'] ) ) { | |
$value = 1; | |
} | |
// Set meta value to either 1 or 0 | |
update_post_meta( $post_id, 'hide_featured_image', $value ); | |
} | |
add_action( 'save_post', 'prefix_save_featured_image_meta', 10, 3 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment