前面的答案不正确。无法使用标签修改后期编辑页面顶部的邮件。您需要使用post_updated_messages
滤器
下面的函数将使用帖子类型的名称自定义消息——如果您使用自定义帖子类型,那么这个函数很方便。这是上示例的修改版本Wordpress Codex.
请注意,视图和预览链接由$viewLink
, $previewLink
, 和$schedPreviewLink
变量,仅当当前帖子的帖子类型的可见性设置为公共时才会显示。
function custom_post_type_messages($messages) {
global $post, $post_ID;
$post_type = get_post_type( $post_ID );
$obj = get_post_type_object($post_type);
$singular = $obj->labels->singular_name;
$viewLink = ($obj->public) ? \' <a href="%s">View \'.strtolower($singular).\'</a>\' : "";
$previewLink = ($obj->public) ? \' <a target="_blank" href="%s">Preview \'.strtolower($singular).\'</a>\': "";
$schedPreviewLink = ($obj->public) ? \' <a target="_blank" href="%2$s">Preview \'.strtolower($singular).\'</a>\': "";
$messages[$post_type] = array(
0 => \'\', // Unused. Messages start at index 1.
1 => sprintf( __($singular.\' updated.\'.$viewLink), esc_url( get_permalink($post_ID) ) ),
2 => __(\'Custom field updated.\'),
3 => __(\'Custom field deleted.\'),
4 => __($singular.\' updated.\'),
5 => isset($_GET[\'revision\']) ? sprintf( __($singular.\' restored to revision from %s\'), wp_post_revision_title( (int) $_GET[\'revision\'], false ) ) : false,
6 => sprintf( __($singular.\' published.\'.$viewLink), esc_url( get_permalink($post_ID) ) ),
7 => __(\'Page saved.\'),
8 => sprintf( __($singular.\' submitted.\'.$previewLink), esc_url( add_query_arg( \'preview\', \'true\', get_permalink($post_ID) ) ) ),
9 => sprintf( __($singular.\' scheduled for: <strong>%1$s</strong>.\'.$schedPreviewLink), date_i18n( __( \'M j, Y @ G:i\' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __($singular.\' draft updated.\'.$previewLink), esc_url( add_query_arg( \'preview\', \'true\', get_permalink($post_ID) ) ) ),
);
return $messages;
}
add_filter(\'post_updated_messages\', \'custom_post_type_messages\' );