Created
July 9, 2015 16:01
-
-
Save bdeleasa/1f034bb344ddabec557d to your computer and use it in GitHub Desktop.
A Wordpress plugin that renames the Featured Image metabox and text.
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 | |
/** | |
* Plugin Name: WP Rename Featured Image | |
* Plugin URI: http://www.briannadeleasa.com | |
* Version: 1.0.0 | |
* Author: Brianna Deleasa | |
* Description: Allows the user to rename the 'Set Featured Image' text and the 'Featured Image' metabox. | |
*/ | |
add_action('admin_head-post-new.php', 'wp_rename_featured_image_admin_head'); | |
add_action('admin_head-post.php', 'wp_rename_featured_image_admin_head'); | |
function wp_rename_featured_image_admin_head( $content ) { | |
if ( 'post' !== $GLOBALS['post_type'] ) { | |
return $content; | |
} | |
add_filter( 'admin_post_thumbnail_html', 'wp_rename_featured_image_post_thumbnail_html' ); | |
add_filter( 'gettext', 'wp_rename_featured_image_rename_use_as', 9999, 4 ); | |
} | |
/** | |
* Renames 'Use as featured image' for our post type | |
* | |
* @param $translation | |
* @param $text | |
* @param $domain | |
* @return mixed | |
* | |
* @since 1.0.0 | |
*/ | |
function wp_rename_featured_image_rename_use_as( $translation, $text, $domain ) { | |
$translations = &get_translations_for_domain( $domain ); | |
if ( $text == 'Use as featured image' ) { | |
return $translations->translate( 'Use as post image' ); | |
} | |
return $translation; | |
} | |
add_filter( 'media_view_strings', 'wp_rename_featured_image_change_featured_image_media_strings', 10, 2); | |
/** | |
* Renames the 'Set featured image' button in the Media Library dialog window. | |
* | |
* @param $strings | |
* @param $post | |
* @return mixed | |
* | |
* @since 1.0.0 | |
*/ | |
function wp_rename_featured_image_change_featured_image_media_strings( $strings, $post ){ | |
if ( $post->post_type !== 'post' ) { | |
return $strings; | |
} | |
$strings['setFeaturedImage'] = __('Set post image', 'feat-img-custom'); | |
$strings['setFeaturedImageTitle'] = __('Set post image', 'feat-img-custom'); | |
return $strings; | |
} | |
/** | |
* If the current page is a 'post', rename the featured image text. | |
* | |
* @param $content | |
* @return mixed | |
* | |
* @since 1.0.0 | |
*/ | |
function wp_rename_featured_image_post_thumbnail_html( $content ) { | |
global $current_screen; | |
if( $current_screen->post_type !== 'post' ) { | |
return $content; | |
} | |
$content = str_replace( __( 'Set featured image' ), __( 'Upload Post Image' ), $content); | |
$content = str_replace( __( 'Remove featured image' ), __( 'Remove Post Image' ), $content); | |
return $content; | |
} | |
add_action( 'do_meta_boxes', 'wp_rename_featured_image_do_meta_boxes' ); | |
/** | |
* Rename the 'Featured Image' metabox. | |
* | |
* @param none | |
* @return none | |
* | |
* @since 1.0.0 | |
*/ | |
function wp_rename_featured_image_do_meta_boxes() { | |
remove_meta_box( 'postimagediv', 'post', 'side' ); | |
add_meta_box( 'postimagediv', __('Post Image'), 'post_thumbnail_meta_box', 'post', 'normal', 'high' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello ,
Good work 👍
This block
function wp_rename_featured_image_post_thumbnail_html( $content ) {
global $current_screen;
if( $current_screen->post_type !== 'post' ) {
return $content;
}
$content = str_replace( __( 'Set featured image' ), __( 'Upload Post Image' ), $content);
$content = str_replace( __( 'Remove featured image' ), __( 'Remove Post Image' ), $content);
return $content;
}
add_action( 'do_meta_boxes', 'wp_rename_featured_image_do_meta_boxes' );
On my case custom_post_type will replace only "Set featured image"
But replacing "Remove featured image" link will not work ...
and I would recommend this block for editing both
// Rename the featured image text.
function rename_set_featured_image( $content ) {
return $content = str_replace( __( 'Set featured image' ), __( 'Set product logo' ), $content );
}
add_filter( 'admin_post_thumbnail_html', 'rename_set_featured_image' );
// Rename the Remove featured image text.
function rename_remove_featured_image( $content ) {
return str_replace( 'Remove featured image', 'Remove product logo', $content );
}
add_filter( 'admin_post_thumbnail_html', 'rename_remove_featured_image', 9999, 1 );
Thank you