Removing Unnecessary Text from Admin Menu without CSS

Here’s an answer to question #1. Not enough time right now to do the rest.

1.) Removing Admin Help Link Button

Unfortunately WordPress doesn’t provide a hook to let you affect the Help Button on the top right of the admin, but you can use a somewhat dirty hack to achieve what you are trying to accomplish.

Now you See It:

Help Link Button in WordPress Admin
(source: mikeschinkel.com)

Now you Don’t:

Help Link Button Removed in WordPress Admin
(source: mikeschinkel.com)

By calling the contextual_help and admin_notices hooks, the ones that are called immediately before and immediately after when the help link button is output, respectively, you can capture the output buffer and remove the offending HTML using preg_replace(). The ob_start()/ob_get_clean() pair of functions in PHP are what you need to buffer output and then to capture that buffered output, viola:

class RemoveAdminHelpLinkButton {
  static function on_load() {
    add_filter('contextual_help',array(__CLASS__,'contextual_help'));
    add_action('admin_notices',array(__CLASS__,'admin_notices'));
  }
  static function contextual_help($contextual_help) {
    ob_start();
    return $contextual_help;
  }
  static function admin_notices() {
    echo preg_replace('#<div id="contextual-help-link-wrap".*>.*</div>#Us','',ob_get_clean());
  }
}
RemoveAdminHelpLinkButton::on_load();

In general you can use this technique to modify or delete almost any HTML output generated by WordPress by finding the before and after hooks but be aware that it is a very fragile technique; if another plugin has modified the HTML output from what you were expecting your preg_replace() could fail to match. Anyway…

3.) Removing Help Text from Page Attributes Metabox

To remove the help text for the Page Attributes metabox doesn’t require regular expressions, a simple str_replace() will do. (Note finding the right hooks to use took the most time.):

class RemovePageAttributesHelpText {
  static function on_load() {
    add_action('admin_notices',array(__CLASS__,'admin_notices'));
    add_action('dbx_post_sidebar',array(__CLASS__,'dbx_post_sidebar'));
  }
  static function admin_notices() {
    ob_start();
  }
  static function dbx_post_sidebar() {
    $match_text="<p>Need help? Use the Help tab in the upper right of your screen.</p>";
    echo str_replace($match_text,'',ob_get_clean());
  }
}
RemovePageAttributesHelpText::on_load();

There’s also another approach you can use when all you want to do it remove text from core and that’s to use the 'gettext' hook. The following code removes the help text from the Page Attributes metabox:

class RemovePageAttributesHelpText {
  static function on_load() {
    add_filter('gettext',array(__CLASS__,'gettext'),10,4);
  }
  function gettext($translation, $text, $domain) {
    if ($text=='Need help? Use the Help tab in the upper right of your screen.') {
      $translation = '';
    }
    return $translation;
  }
}
RemovePageAttributesHelpText::on_load();

Note that I’m cautious to use this hook as it gets called hundreds of times per page load; 577 times just to load the Admin Dashboard in case I just tested, for example. So if you use it be sure not to do anything that is computationally “expensive” such as running a raw SQL query or similar.

4.) Removing Text from the “Excerpt Metabox”

We’ll use option #2 from technique #3 to strip the help text from the Excerpt Metabox (this one I included the code from technique #3 so this one replaces the code in #3):

class RemoveUnwantedPageEditingText {
  static function on_load() {
    add_action('admin_notices',array(__CLASS__,'admin_notices'));
    add_action('dbx_post_sidebar',array(__CLASS__,'dbx_post_sidebar'));
  }
  static function admin_notices() {
    ob_start();
  }
  static function dbx_post_sidebar() {
    $html = str_replace('<p>Need help? Use the Help tab in the upper right of your screen.</p>','',ob_get_clean());
    echo str_replace('Excerpts are optional hand-crafted summaries of your content that can be used in your theme.' .
     ' <a href="http://codex.wordpress.org/Excerpt" target="_blank">Learn more about manual excerpts.</a>','',$html);
  }
}
RemoveUnwantedPageEditingText::on_load();

Leave a Comment