如何在WordPress帖子编辑器中更改帖子“摘录”框标签的文本?

时间:2011-07-12 作者:N2Mystic

我的主题让网站所有者可以选择使用每篇文章的“摘录”字段来填写每页的“元描述”标签。

如果我可以过滤在post编辑器中查看时显示在默认摘录输入控件上的文本标签和描述文本,这将非常有用。

是否有过滤器或挂钩?

或者,我想我可以使用jQuery通过DOM做一些事情。

3 个回复
最合适的回答,由SO网友:Bainternet 整理而成

您可以使用一个过滤器挂钩gettext此处:

add_filter( \'gettext\', \'wpse22764_gettext\', 10, 2 );
function wpse22764_gettext( $translation, $original )
{
    if ( \'Excerpt\' == $original ) {
        return \'My Excerpt label\';
    }else{
        $pos = strpos($original, \'Excerpts are optional hand-crafted summaries of your\');
        if ($pos !== false) {
            return  \'My Excerpt description\';
        }
    }
    return $translation;
}

SO网友:Arman H

如果有人试图添加特定的帖子类型,您可以尝试以下代码

add_filter(\'gettext\', \'mana_pharmacy_video_link_excerpt_rename\', 10, 2);
function mana_pharmacy_video_link_excerpt_rename($translation, $original)
{
    if (get_post_type( ) == \'video_link\') {
        if (\'Excerpt\' == $original) {
            return \'Add Video Link\';
        } else {
            $pos = strpos($original, \'Excerpts are optional hand-crafted summaries of your\');
            if ($pos !== false) {
                return  \'Add any video link in the box above\';
            }
        }
    }
    return $translation;
}

SO网友:millionleaves

我使用了原始答案,并对其进行了修改,以处理不同的帖子类型:

// Customise the Excerpt field title and description via WP translation.
// Change the $post_types array to change the default Excerpt metabox title and description. The description is generic but substitutes the post_type to make it specific to the current post type.

add_filter( \'gettext\', \'change_excerpt_info\', 10, 2 );

function change_excerpt_info ( $translation, $original ) {
    $post_types = array( "service", "workshop", \'team\' );
    $post = get_post( $post );
    $posttype = \'\';
    if ( $post ) {
        $posttype =  $post->post_type;
    }
    if ( in_array($posttype, $post_types) ) {
        if ( \'Excerpt\' == $original ) {
             return ucfirst($posttype) . \' Teaser\'; // Will appear as Service Teaser, Team Teaser, etc.
        } else $pos = strpos($original, \'Excerpts are optional hand-crafted summaries\');
        if ($pos !== false) {
            // The Summary will incorporate the post_type into the description.
            $summary = \'This field will be displayed as a teaser or summary of anywhere this \' . $posttype . \' appears in a grid layout. You should always write a teaser of about 30 words. It will never be displayed on the actual \' . $posttype . \' page, so you can repeat content from other fields on this editing screen if you want.\';
              return $summary;
        }
    }
    return $translation;
}

结束

相关推荐

为什么这段jQuery代码不能工作?

把我的头发扯下来一点!我正在尝试创建多个图像选择框,以便用户可以将任意多个图像上传到他们创建的物种档案中。我在中使用以下代码。js文件:jQuery(文档)。就绪(函数(){ var i = 2; jQuery(\'a#add_media\').click(function() { input_code = \'<p>\' + \'<input id=\"upload_image-\' + i + \