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

Eri*_*edo 5 wordpress wordpress-plugin

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

预习:

在此输入图像描述

Lem*_*azi 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 );
Run Code Online (Sandbox Code Playgroud)

您也可以申请以下代码

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 );
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


小智 5

首先,查看您当前的管理菜单。我通常用一个临时代码来做到这一点,我将其插入到我的主题的 function.php 中

add_action( 'admin_menu', 'myRenamedPlugin' );

function myRenamedPlugin() {
    global $menu;
    print_r($menu);
}
Run Code Online (Sandbox Code Playgroud)

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

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
        )
...
Run Code Online (Sandbox Code Playgroud)

在此数组中,找到要重命名的插件。例如插件“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
    )
Run Code Online (Sandbox Code Playgroud)

您会看到,位置 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
}
Run Code Online (Sandbox Code Playgroud)