我注册了自定义帖子类型名称Banks。
我可以更改此帖子类型后缩略图元框标题和文字值吗?
这可能吗?
答案 0 :(得分:4)
更容易理解:
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');
}
主要思想是:重新声明具有所需标题的元框。 替换要为其编辑默认“特色图片”标签的帖子类型。
答案 1 :(得分:3)
我刚刚发现了闷热。
这是一个例子。
add_action( 'admin_head', 'remove_my_meta_boxen' );
function remove_my_meta_boxen() {
remove_meta_box( 'postimagediv', 'banks', 'side' );
add_meta_box('postimagediv', __('Add a bank image'), 'post_thumbnail_meta_box', 'banks', 'side', 'high');
}
快乐的编码。
答案 2 :(得分:2)
<?php
/*
* Change the featured image metabox title text
*/
function km_change_featured_image_metabox_title() {
remove_meta_box( 'postimagediv', 'my_post_type_name', 'side' );
add_meta_box( 'postimagediv', __( 'NEW TITLE TEXT', 'km' ), 'post_thumbnail_meta_box', 'my_post_type_name', 'side' );
}
add_action('do_meta_boxes', 'km_change_featured_image_metabox_title' );
/*
* Change the featured image metabox link text
*
* @param string $content Featured image link text
* @return string $content Featured image link text, filtered
*/
function km_change_featured_image_text( $content ) {
if ( 'my_post_type_name' === get_post_type() ) {
$content = str_replace( 'Set featured image', __( 'NEW SET TEXT HERE', 'km' ), $content );
$content = str_replace( 'Remove featured image', __( 'NEW REMOVE TEXT HERE', 'km' ), $content );
}
return $content;
}
add_filter( 'admin_post_thumbnail_html', 'km_change_featured_image_text' );
答案 3 :(得分:0)
好!使用不同的钩子,使用相同错误方法的多个答案的旧问题!如果有人需要,我会发布一种更好的方法,而无需使用额外的钩子或编辑元框。
使用register_post_type
函数注册新的CPT时,我们可以(并且应该!)将labels
数组传递给它的参数。其中一些标签用于CPT编辑屏幕。
$labels = [
'name' => __( 'Banks', 'textdomain' ),
'singular_name' => __( 'Bank', 'textdomain' ),
'add_new' => __( 'Add New', 'textdomain' ),
'add_new_item' => __( 'Add New Bank', 'textdomain' ), //used in post-new.php?post_type=bank
'edit_item' => __( 'Edit Bank', 'textdomain' ), //used in post.php
'new_item' => __( 'New Bank', 'textdomain' ),
'all_items' => __( 'All Banks', 'textdomain' ),
'view_item' => __( 'Vew Bank', 'textdomain' ),
'search_items' => __( 'Search Banks', 'textdomain' ),
'not_found' => __( 'No banks found', 'textdomain' ),
'not_found_in_trash' => __( 'No banks found in trash', 'textdomain' ),
'parent_item_colon' => __( 'Parent bank', 'textdomain' ),
'menu_name' => __( 'Banks', 'textdomain' ),
'featured_image' => __( 'Bank image', 'textdomain' ), //used in post.php
'set_featured_image' => __( 'Set bank image', 'textdomain' ), //used in post.php
'remove_featured_image' => __( 'Remove bank image', 'textdomain' ), //used in post.php
'use_featured_image' => __( 'Use as bank image', 'textdomain' ), //used in post.php
'insert_into_item' => __( 'Insert into bank', 'textdomain' ), //used in post.php
'uploaded_to_this_item' => __( 'Uploaded to this bank', 'textdomain' ), //used in post.php
'filter_items_list' => __( 'Filter banks', 'textdomain' ),
'items_list_navigation' => __( 'Banks navigation', 'textdomain' ),
'items_list' => __( 'Banks list', 'textdomain' ),
];
$args = [
'description' => 'Bank CPT',
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => false,
'has_archive' => false,
'labels' => $labels,
'supports' => ['thumbnail'],
'query_var' => false,
'can_export' => true,
'show_in_rest' => false,
];
register_post_type('bank', $args);