我不想为了改变用户输入新帖子的页面而编辑核心文件,所以有没有一种方法可以在一个主题中,或者在函数中这样做。php。。?
具体来说,我正在尝试将“设置特色图像”文本的措辞更改为类似“设置特色图像-50像素乘以50像素”
我不想为了改变用户输入新帖子的页面而编辑核心文件,所以有没有一种方法可以在一个主题中,或者在函数中这样做。php。。?
具体来说,我正在尝试将“设置特色图像”文本的措辞更改为类似“设置特色图像-50像素乘以50像素”
您可以使用过滤器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\' );
一种方法是使用插入管理员标题中的谨慎jQuery代码来修改页面特定部分中的文本。要做到这一点,您需要能够针对特定的div/span/html标记,但此系统将允许您编辑页面的任何部分,即使没有过滤器(虽然索里奇的答案对您问题中的用例有很好的过滤器,但我的答案更普遍地适用于您的问题本身)。
我使用下面的代码将2.9中的特色图像框改为“特色图像”,而不是“张贴缩略图”,因为标签在3.0中更改了,我希望我的旧站点在升级之前使用新术语。
请注意,该代码处理弹出框和元框,并使用一些jquery AJAX函数确保在iframe中加载页面后重新修改内容。
/**
* 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\');
更简单的解决方案:
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“标签。我的w-admin登录有一个奇怪的问题。这是从我升级到3.0以后才开始的,当我转到wp admin时,登录表单显示正常,但当我输入用户名并通过时,每次都会再次显示登录表单。使用密码恢复功能会导致电子邮件未找到错误。我知道用户名密码和电子邮件是正确的,b/c我可以访问mysql数据库,我可以看到值(至少用户名和电子邮件) 有人知道会出什么问题吗