如何重命名插件标题> Wordpress>仪表板

时间:2015-12-02 17:59:20

标签: wordpress wordpress-plugin

拜托,有人可以帮帮我吗?我需要更改我的wordpress中安装的插件的名称(只有管理栏中的名称很好;)。谢谢!

预览:

enter image description here

5 个答案:

答案 0 :(得分:10)

以下是更改标签的过程(我将WooCommerce更改为" Stall"在我的示例中)。 您可以通过以下方式使用gettext filter进行尝试。

functions.php 文件

中使用此功能
function rename_header_to_logo( $translated, $original, $domain ) {

$strings = array(
    'WooCommerce' => 'Stall',
    'Custom Header' => 'Custom Stall'
);

if ( isset( $strings[$original] ) && is_admin() ) {
    $translations = &get_translations_for_domain( $domain );
    $translated = $translations->translate( $strings[$original] );
}

  return $translated;
}

add_filter( 'gettext', 'rename_header_to_logo', 10, 3 );

您也可以申请以下代码

function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
    case 'WooCommerce' :
        $translated_text = __( 'Stall', 'woocommerce' );
        break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

enter image description here

答案 1 :(得分:2)

首先,查看您当前的管理菜单。我通常使用临时代码执行此操作,我将其插入到主题的function.php

add_action( 'admin_menu', 'myRenamedPlugin' );

function myRenamedPlugin() {
    global $menu;
    print_r($menu);
}

现在,当您登录时,管理员菜单的完整树在源代码中可见,并且看起来像这样:

Array
(
    [2] => Array
        (
            [0] => Dashboard
            [1] => read
            [2] => index.php
            [3] =>
            [4] => menu-top menu-top-first menu-icon-dashboard menu-top-last
            [5] => menu-dashboard
            [6] => div
        )

    [4] => Array
        (
            [0] =>
            [1] => read
            [2] => separator1
            [3] =>
            [4] => wp-menu-separator
        )
...

在此数组中,找到要重命名的插件。例如插件“Wordpress文件”

[101] => Array
    (
        [0] => Wordpress Files
        [1] => read
        [2] => pgl_wp_files
        [3] => WP Files
        [4] => menu-top menu-icon-generic
        [5] => toplevel_page_pgl_wp_files
        [6] => dashicons-admin-generic
    )

你知道,在位置2是插件的唯一名称“pgl_wp_files”。通过使用插件的唯一名称,我们避免重命名具有类似名称的其他插件。因此,这一额外步骤很重要。

现在,我们在函数中将此值用作搜索针。一旦找到,它就可以用我们想要的任何名称替换插件的名称(位置0)。

简化:使用以下内容替换主题function.php中的上述功能:

add_action( 'admin_menu', 'myRenamedPlugin' );

function myRenamedPlugin() {

    global $menu;
    $searchPlugin = "pgl_wp_files"; // Use the unique plugin name
    $replaceName = "New Name for Plugin";

    $menuItem = "";
    foreach($menu as $key => $item){
        if ( $item[2] === $searchPlugin ){
            $menuItem = $key;
        }
    }
    $menu[$menuItem][0] = $replaceName; // Position 0 stores the menu title
}

答案 2 :(得分:0)

您可以在插件代码中更改一行来编辑此内容!虽然很难确切说明它会在哪里,因为它取决于插件。

如果您的插件位于侧边栏的顶层(即它不在下拉列表中或任何内容中),请尝试搜索插件文件夹(wp-content / plugins / whatever-plugin-name)名为add_menu_page的函数。该函数的第二个参数是"菜单标题",所以只需将其中的任何内容更改为您想要的任何内容。

详细信息:https://codex.wordpress.org/Function_Reference/add_menu_page

如果它在下拉列表中,请尝试搜索名为add_submenu_page的函数。在此函数中,菜单中的文本是THIRD参数,因此请保留第二个参数并将第三个参数更改为所需的标题。

如果找不到add_submenu_page,请在此列表中搜索add_plugins_pageadd_theme_page或其他人:https://codex.wordpress.org/Function_Reference/add_submenu_page,具体取决于您的插件所在的子菜单#39;页面实际上在。

重要编辑:如果插件使用其中一个'快捷方式'函数,然后侧栏中页面的名称再次是SECOND参数。

答案 3 :(得分:0)

作为@ DrAnd1的改进,以下是一个重命名多个元素的函数:

function replace_admin_menu() {
    global $menu;
    //var_dump($menu);
    $translations = [
        "pgl_wp_files" => "new name for Plugin",
        "WooCommerce" => "Stall",
    ];
    foreach ($translations as $keyToTranslate => $valueTranslated) {
        $menuItem = null;
        foreach ($menu as $key => $item) {
            if ($item[2] === $keyToTranslate) {
                $menuItem = $key;
            }
        }
        if ($menuItem)
            $menu[$menuItem][0] = $valueTranslated;
    }
}

add_action('admin_menu', 'replace_admin_menu');

答案 4 :(得分:0)

add_action( 'admin_menu', 'rename_woocoomerce', 999 );
function rename_woocoomerce(){
    global $menu;

// Pinpoint menu item
    $woo = rename_woocommerce( 'WooCommerce', $menu );

    // Validate
    if( !$woo )
        return;
        $menu[$woo][0] = 'Store Settings';
        }

function rename_woocommerce( $needle, $haystack )
{
foreach( $haystack as $key => $value )
    {
        $current_key = $key;
        if(
            $needle === $value
            OR (
                is_array( $value )
                && rename_woocommerce( $needle, $value ) !== false
                )
        )
        {
            return $current_key;
        }
    }
    return false;
}