web-dev-qa-db-ja.com

Wp-adminバックエンドの文言を変更するにはどうすればいいですか?

ユーザーが新しい投稿を入力したページを変更するためにコアファイルを編集したくないのですが、テーマの中で(おそらくfunctions.phpの中で)編集する方法はありますか?

具体的には、「おすすめ画像の設定」テキストの用語を「おすすめ画像の設定 - 50 x 50ピクセル」のように変更しようとしています。

4
cannyboy

フィルタadmin_post_thumbnail_htmlを使うことができます。

function custom_admin_post_thumbnail_html( $content ) {
    return $content = str_replace( __( 'Set featured image' ), __( 'Set featured image - 50 pixels by 50 pixels' ), $content );
}

add_filter( 'admin_post_thumbnail_html', 'custom_admin_post_thumbnail_html' );
11
sorich87

1つの方法は、管理者のヘッダーに挿入された慎重なjQueryコードを使用して、ページの特定の部分内のテキストを変更することです。そのためには、特定のdiv/span/htmlタグをターゲットに設定できる必要がありますが、このシステムでは、フィルタがなくてもページの任意の部分を編集できます(ただし、Sorichによる回答には素晴らしいフィルタがあります)。あなたの質問のユースケース、私の答えはあなたの質問自体にもっと一般的に当てはまります。

ラベルは3.0で変更されたため、アップグレード前に新しい用語を使用するようにしたいので、2.9の機能付き画像ボックスを「サムネイルの後」ではなく「機能付き画像」と表示するように変更しました。

コードはポップアップボックスとメタボックスの両方を処理し、iframeでのページロード後にコンテンツが確実に再編集されるようにjquery AJAX関数を使用していることに注意してください。

/**
 * Use jQuery to add context to the Featured Image metabox on post editing pages
 * and to change the label to be Featured Image instead of Post thumbnail in WP 2.9 
 * before the label changed.
 *
 * See javascript for info on removing these as they become part of the AP API
 */
function gv_admin_featured_image_tweaks() {
    ?>
<script type="text/javascript">
    jQuery(document).ready(function($) {
        /**
         * TEMPORARY: SWITCH VARIOUS LABELS TO SHOW FEATURED IMAGE INSTEAD OF POST THUMBNAIL
         * REMOVE WHEN 3.0 COMES OUT AND THIS IS THE DEFAULT LABEL
         */
        $('#postimagediv h3 span').text('Featured Image');
        // Only change the set thumbnail text if its that, otherwise we end up replacing the img tag when it is set
        if ($('#postimagediv #set-post-thumbnail').text() == 'Set thumbnail') {
            $('#postimagediv #set-post-thumbnail').text('Choose Featured Image');
        }
        $('#postimagediv #remove-post-thumbnail').text('Remove Featured Image');

        // label inside media item details in popup
        $('.wp-post-thumbnail').text('Use as Featured Image');
        // refresh inside media item for after upload finishes.
        $('body').ajaxComplete(function() {
            $('.wp-post-thumbnail').text('Use as Featured Image');
        });

        /**
         * Add a description of how we use featured images. should be replaced with a description parameter in the API
         */
        $('#postimagediv .inside').prepend('<p>This image will be used in the featured posts slider if this post is featured. It should be at least 400px wide by 300px tall.</p>');
    });
</script>
    <?php
}
add_action('admin_head', 'gv_admin_featured_image_tweaks');
5
jerclarke

ここでより簡単な解決策:

add_action( 'admin_head', 'replace_default_featured_image_meta_box', 100 );
function replace_default_featured_image_meta_box() {
    remove_meta_box( 'postimagediv', 'my-post-type-here', 'side' );
    add_meta_box('postimagediv', __('My Cover Image'), 'post_thumbnail_meta_box', 'my-post-type-here', 'side', 'high');
}

主な考え方は、必要なタイトルでメタボックスを再宣言することです。デフォルトの " Featured Image "ラベルを編集したい投稿タイプを置き換えます。

0
Reza Mamun