Please, may someone help me? I need change the name of a plugin installed in my wordpress (Only the name in the admin bar is fine ;) . Thanks!
Preview:
Please, may someone help me? I need change the name of a plugin installed in my wordpress (Only the name in the admin bar is fine ;) . Thanks!
Preview:
Here's the process to change the labels (I changed WooCommerce to "Stall" in my example).
You could try that with the gettext filter
in the following manner.
Use this in your functions.php file
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 );
Also you can apply below code
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 );
First, have a look at your current admin menu. I usually do that with a temporary code, which I insert into my theme's function.php
add_action( 'admin_menu', 'myRenamedPlugin' );
function myRenamedPlugin() {
global $menu;
print_r($menu);
}
Now, when you are logged in, the complete tree of your admin menu is visible in the source code and will look something like this:
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
)
...
In this array, find the plugin that you want to rename. For example the Plugin "Wordpress Files"
[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
)
You see, at position 2 is the plugin's unique name "pgl_wp_files". By using the plugin's unique name, we avoid that other plugins with a similar name are going to be renamed. Hence, this extra step was important.
Now, we use this value in our function as a search needle. Once found, it can replace the plugin's name (position 0) with whatever name we like to have.
To make it short: Replace the above function in your theme's function.php with the following:
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
}
There's a line you can change in the plugin code to edit this! It's hard to say exactly where it will be though, because it depends on the plugin.
If your plugin is on the top level of the sidebar (i.e. it's not in a dropdown or anything), try searching through the plugin folder (wp-content/plugins/whatever-plugin-name) for a function called add_menu_page
. The second argument of that function is the "menu title", so just change whatever's in there to whatever you want it to be.
Details: https://codex.wordpress.org/Function_Reference/add_menu_page
If it's under a dropdown, try searching for a function called add_submenu_page
. In this function, the text in the menu is the THIRD argument, so leave the second argument alone and change the third argument to your desired title.
If you can't find add_submenu_page
, search for add_plugins_page
or add_theme_page
or one of the others on this list: https://codex.wordpress.org/Function_Reference/add_submenu_page depending on what submenu your plugin's page is actually in.
important edit: If the plugin uses one of these 'shortcut' functions, then the name of the page in the sidebar is the SECOND argument again.
As an improvement of @DrAnd1, here's a function to rename multiple elements:
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');