2

I'm developing a plugin that I'll install for all my clients to make WordPress slightly easier to use for them. One of the things it will change is name of the W3 Total Cache Admin menu from "Performance" to "Ytelse (avansert)".

I know how to rename the default admin menus. The code below changes "Posts" to "Nyheter"(News in Norwegian).

function change_post_menu_label_news() {
global $menu;
$menu[5][0] = 'Nyheter';
echo '';
}

add_action( 'admin_menu', 'change_post_menu_label_news' );

I find the ID to change by temporarily using this code:

add_action('admin_init','dump_admin_menu');
function dump_admin_menu() {
 if (is_admin()) {
header('Content-Type:text/plain');
var_dump($GLOBALS['menu']);
exit;
}
}

However, it's harder to rename the Performance menu since the ID increments by one when I try to rename it!. W3 Total Cache probably thinks that the ID is taken and tries a higher one.

How can I change the name of the W3 Total Cache admin Menu while avoiding this issue and without editing anything related to the plugin?

  • first are you sure that it is not just an echo or text? if thats the case you need to edit the file for it. – xLRDxREVENGEx May 20 '11 at 5:58
2

You may be able to use the WordPress filter 'gettext':

http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext

add_filter( 'gettext', 'rename_menu_item' );
function rename_menu_item( $translated ) 
{
    $translated = str_replace( 'Performance', 'Ytelse', $translated );
    return $translated;
}
1

jQuery is your friend.

jQuery(document).ready(function() {
jQuery('a.toplevel_page_w3tc_general').text('Ytelse (avansert)');
});

Working example: http://jsfiddle.net/c3mdigital/Lq7UX/4/

0

I used your code to locate W3 Total Cache in the $menu array (in my case it was 102), I then copy / pasted your code to change the label, and these were the results:

screenshot

I realize I got the wrong label here, but this otherwise appears to be correct, menu works as expected.

  • HM, weird. My ID started at 100, now it has incremented up to 104 – kristofferR May 20 '11 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.