Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking for a way to remove all the unessesary text from default worpdress metaboxes.

Preferably I would like to ensure that the content is not just hidden through CSS but actually removed from the HTML so it does not even show up in the source.

The areas I am interested in removing include:

  1. The HELP button on the top right and associating DIV/HTML/text when you click on it
  2. On the Dashboard in the Right Now Metabox I want to remove the text related to which theme is being used and the version of wordpress as well as the change theme button.
  3. On the "Page Attributes" metabox on the bottom it has the text "Need help? Use the Help tab in the upper right of your screen." I would like for this text to be removed
  4. Under the "Excerpt Metabox" there is text which I would like to remove
  5. Any other text which you might also know how to remove to cleanup wordpress.
share|improve this question
    
Hi @NetConstructor: You are asking 5 different questions here. Since the solution is different for each how about asking 5 different questions each with a well-named title? If you do then answering one of those questions won't feel like such a big job and maybe different people can answer different questions. Just a thought... –  MikeSchinkel Sep 30 '10 at 5:48
    
@NetConstructor.com - How's this for irony? My main client asked me to do a lot of this same types of things on my main project today. They want anything related to WordPress to become invisible in the admin. I had to chuckle... ;-) –  MikeSchinkel Oct 14 '10 at 6:30
    
@Mike -- Ha! So, I am curious to now know what else you might have have done as I have hacked stuff together over time to achieve this. Some of outstanding things which I really wanted to achieve were. 1) Hiding /wp-admin and /wp-login.php so they can't be accessed. 2) Creating a function would would auto change all wordpress assigned classes and ids to something else 3) most important one i can't figure out was how to change get_bloginfo('stylesheet_directory') and/or get_bloginfo('template_directory') and other default calls to automatically remove wp-content/theme-name from the printed url –  NetConstructor.com Oct 14 '10 at 22:28
    
@NetConstructor.com - Those are a lot harder because they are involved in how to site operates. Comparatively, removing text is easy. I'm curious, why do you want to do this? In my client's case they are selling what I am writing as their product and think having it be WordPress devalues it in the eyes of their customers (which is unfortunately probably true.) –  MikeSchinkel Oct 14 '10 at 22:42
    
@Mike -- True, from my experience, some companies that have heard about wordpress has been told that it sucks or that its a bad choice. While I would have to agree that for large sites and/or those which lots of custom queries this is correct in most cases i have found wordpress is more than perfect. Anyway... for a larger firm where I feel wordpress is a good choice they generally like a more customized solution even if its only cosmetic. –  NetConstructor.com Oct 15 '10 at 4:55

3 Answers 3

up vote 5 down vote accepted

Hi @NetConstructor:

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

Now you Don't:

Help Link Button Removed in WordPress Admin

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();
share|improve this answer
    
@mikeschinkel -- Thank you very much for your input here. I feel that if I understand this a bit better I can use this to achieve what I need to do without having to just hide the metaboxes through css which is what I was doing. I did notice however that when I integrate the code into my functions.php file it the html of the page still includes the class="metabox-prefs" along with all the help content information. Could you possibly show me how I would go about removing that as well. I essentially don't want any mention of the help visually or in the html –  NetConstructor.com Sep 30 '10 at 10:02
    
@NetConstructor.com: Do you see the preg_replace()? Wrap it's output with another preg_replace(), this time targeting <div class="metabox-prefs"></div>. (I assumed you'd know RegEx; is that not something you are able to modify yourself?) –  MikeSchinkel Oct 2 '10 at 2:42
    
@mikeschinkel -- i think the only thing which confused me here was how you entered #Us in the code within your answer... Could you briefly explain that one? –  NetConstructor.com Oct 4 '10 at 1:28
    
@NetConstructor.com - Good catch. Those are RegEx modifiers (bit.ly/php-regex-modifiers) Capital "U" is "Ungreedy" meaning don't keep trying to find a closing </div> farther away, use the first one you get. Lowercase "s" means to match across carriage returns and line feeds, i.e. do a "multiline" match. BTW, I had to figure those out the hard way; nobody (else) seems to explain those anywhere, at least not in context. HTH. –  MikeSchinkel Oct 4 '10 at 7:31
    
@mikeschinkel -- hmmm... very interesting. Thats the first time I have heard about the use of that. I was playing around with this but I am having a difficult time figuring out how to apply this logic to remove the text for the "page attributes" metabox without messing up other <p> tags used in there. Whats the best course of action there? match the full text to ensure it does not remove things related to other potential plugins which modify that area? How would you go about writing this code? Could you possibly show it so I can learn your way? –  NetConstructor.com Oct 7 '10 at 11:02

Alternativ and very easy: use the plugin Adminimize, this plugin have many options and you can add your own options. This plugin is my own and i will coding a newer plugin with better code. Maybe its help for a csutom solution to read the source.

share|improve this answer
    
@bueltge your plugin works nicely, but is only a good answer for someone who is an end user and not someone who actually wants to know how to write the code. BTW, whenever you suggest your own plugins please make it clear that they are yours. I'm sure it was an oversight on your part (I know you are not a spammer) but it's harder to take spammers to task when we don't ask everyone to follow the rules. Nothing wrong with suggesting your own plugins where applicable but better for it to just be clear that it's your own plugin and not a 3rd party endorsement. –  MikeSchinkel Oct 2 '10 at 2:49
    
@Mike: yes, im not a spamer - but i had understand the question on the top, so that the user search for an easy way, not for a coding way. I can also write solutions for the question via custom plugin or in the theme, but i had understand the ask a bit different. Sorry, when the link to the plugin is an spam-comment. –  bueltge Oct 2 '10 at 18:43
1  
@bueltge - @NetConstuctor.com has asked tons of questions and it seems that he's interested in how to code things. I've noticed that, you probably haven't so my bad. But do please mention that if you are suggesting your own plugins that they are in fact your plugins; that'll keep everything on the up-and-up. –  MikeSchinkel Oct 2 '10 at 21:30
    
Thanks Mike, i will remember this on my next comment. Maybe it is importatn, that i read the question better and train my english. –  bueltge Oct 2 '10 at 21:36
    
@bueltge Just in case, please don't take any of this personally; we're just trying to moderate a bit. Over the years you have been are a wonderful contributor to the WordPress community. Also I only wish my German were 1/100th as good as your English. :) –  MikeSchinkel Oct 4 '10 at 7:33

Jake Goldman's excellent talk at WordCamp Mid-Atlantic provides an excellent guide: http://www.cmurrayconsulting.com/wordpress-tips/customizing-wordpress-admin/#more-939

Download the well-commented theme that appears below the slideshow. (He asks that if you use his code, you please attribute it to him in your code comments.)

He mentions that you can get all the widget IDs as follows: var_dump( $wp_meta_boxes['dashboard'] );

You could: unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);

Then add your own widget using wp_add_dashboard_widget().

Look in wp-admin/includes/dashboard.php for the function, wp_dashboard_right_now() for a model for what to add (deleting theme info, as desired.)

functions.php

<?php
/*
Based on Jake Goldman's approach
*/

add_action('wp_dashboard_setup', 'custom_dashboard_widgets');

function custom_dashboard_widgets(){
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
wp_add_dashboard_widget('my_dashboard_right_now', 'Right Now', 'right_now_no_theme'); 
}

function right_now_no_theme() {
        global $wp_registered_sidebars;

        $num_posts = wp_count_posts( 'post' );
        $num_pages = wp_count_posts( 'page' );

        $num_cats  = wp_count_terms('category');

        $num_tags = wp_count_terms('post_tag');

        $num_comm = wp_count_comments( );

        echo "\n\t".'<div class="table table_content">';
        echo "\n\t".'<p class="sub">' . __('Content') . '</p>'."\n\t".'<table>';
        echo "\n\t".'<tr class="first">';

        // Posts
        $num = number_format_i18n( $num_posts->publish );
        $text = _n( 'Post', 'Posts', intval($num_posts->publish) );
        if ( current_user_can( 'edit_posts' ) ) {
                $num = "<a href='edit.php'>$num</a>";
                $text = "<a href='edit.php'>$text</a>";
        }
        echo '<td class="first b b-posts">' . $num . '</td>';
        echo '<td class="t posts">' . $text . '</td>';

        echo '</tr><tr>';
        /* TODO: Show status breakdown on hover
        if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds.  Don't show if !current_user_can
                $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( _n( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
        }
        if ( $can_edit_posts && !empty($num_posts->draft) ) {
                $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( _n( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>';
        }
        if ( $can_edit_posts && !empty($num_posts->future) ) {
                $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( _n( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>';
        }
        if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
                $pending_text = sprintf( _n( 'There is <a href="%1$s">%2$s post</a> pending your review.', 'There are <a href="%1$s">%2$s posts</a> pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) );
        } else {
                $pending_text = '';
        }
        */

        // Pages
        $num = number_format_i18n( $num_pages->publish );
        $text = _n( 'Page', 'Pages', $num_pages->publish );
        if ( current_user_can( 'edit_pages' ) ) {
                $num = "<a href='edit.php?post_type=page'>$num</a>";
                $text = "<a href='edit.php?post_type=page'>$text</a>";
        }
        echo '<td class="first b b_pages">' . $num . '</td>';
        echo '<td class="t pages">' . $text . '</td>';

        echo '</tr><tr>';

        // Categories
        $num = number_format_i18n( $num_cats );
        $text = _n( 'Category', 'Categories', $num_cats );
        if ( current_user_can( 'manage_categories' ) ) {
                $num = "<a href='edit-tags.php?taxonomy=category'>$num</a>";
                $text = "<a href='edit-tags.php?taxonomy=category'>$text</a>";
        }
        echo '<td class="first b b-cats">' . $num . '</td>';
        echo '<td class="t cats">' . $text . '</td>';

        echo '</tr><tr>';

        // Tags
        $num = number_format_i18n( $num_tags );
        $text = _n( 'Tag', 'Tags', $num_tags );
        if ( current_user_can( 'manage_categories' ) ) {
                $num = "<a href='edit-tags.php'>$num</a>";
                $text = "<a href='edit-tags.php'>$text</a>";
        }
        echo '<td class="first b b-tags">' . $num . '</td>';
        echo '<td class="t tags">' . $text . '</td>';

        echo "</tr>";
        do_action('right_now_content_table_end');
        echo "\n\t</table>\n\t</div>";


        echo "\n\t".'<div class="table table_discussion">';
        echo "\n\t".'<p class="sub">' . __('Discussion') . '</p>'."\n\t".'<table>';
        echo "\n\t".'<tr class="first">';

        // Total Comments
        $num = '<span class="total-count">' . number_format_i18n($num_comm->total_comments) . '</span>';
        $text = _n( 'Comment', 'Comments', $num_comm->total_comments );
        if ( current_user_can( 'moderate_comments' ) ) {
                $num = '<a href="edit-comments.php">' . $num . '</a>';
                $text = '<a href="edit-comments.php">' . $text . '</a>';
        }
        echo '<td class="b b-comments">' . $num . '</td>';
        echo '<td class="last t comments">' . $text . '</td>';

        echo '</tr><tr>';

        // Approved Comments
        $num = '<span class="approved-count">' . number_format_i18n($num_comm->approved) . '</span>';
        $text = _nx( 'Approved', 'Approved', $num_comm->approved, 'Right Now' );
        if ( current_user_can( 'moderate_comments' ) ) {
                $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
                $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>$text</a>";
        }
        echo '<td class="b b_approved">' . $num . '</td>';
        echo '<td class="last t">' . $text . '</td>';

        echo "</tr>\n\t<tr>";

        // Pending Comments
        $num = '<span class="pending-count">' . number_format_i18n($num_comm->moderated) . '</span>';
        $text = _n( 'Pending', 'Pending', $num_comm->moderated );
        if ( current_user_can( 'moderate_comments' ) ) {
                $num = "<a href='edit-comments.php?comment_status=moderated'>$num</a>";
                $text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>$text</a>";
        }
        echo '<td class="b b-waiting">' . $num . '</td>';
        echo '<td class="last t">' . $text . '</td>';

        echo "</tr>\n\t<tr>";

        // Spam Comments
        $num = number_format_i18n($num_comm->spam);
        $text = _nx( 'Spam', 'Spam', $num_comm->spam, 'comment' );
        if ( current_user_can( 'moderate_comments' ) ) {
                $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
                $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>$text</a>";
        }
        echo '<td class="b b-spam">' . $num . '</td>';
        echo '<td class="last t">' . $text . '</td>';

        echo "</tr>";
        do_action('right_now_table_end');
        do_action('right_now_discussion_table_end');
        echo "\n\t</table>\n\t</div>";

        echo "\n\t".'<div class="versions">';
        $ct = current_theme_info();

        echo "\n\t<p>";
/*
        if ( !empty($wp_registered_sidebars) ) {
                $sidebars_widgets = wp_get_sidebars_widgets();
                $num_widgets = 0;
                foreach ( (array) $sidebars_widgets as $k => $v ) {
                        if ( 'wp_inactive_widgets' == $k )
                                continue;
                        if ( is_array($v) )
                                $num_widgets = $num_widgets + count($v);
                }

                $num = number_format_i18n( $num_widgets );
                $switch_themes = $ct->title;
                if ( current_user_can( 'switch_themes') ) {
                        echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
                        $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
                }
                if ( current_user_can( 'edit_theme_options' ) ) {
                        printf(_n('Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $switch_themes, $num);
                } else {
                        printf(_n('Theme <span class="b">%1$s</span> with <span class="b">%2$s Widget</span>', 'Theme <span class="b">%1$s</span> with <span class="b">%2$s Widgets</span>', $num_widgets), $switch_themes, $num);
                }
        } else {
                if ( current_user_can( 'switch_themes' ) ) {
                        echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
                        printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title );
                } else {
                        printf( __('Theme <span class="b">%1$s</span>'), $ct->title );
                }

        }
*/
        echo '</p>';

        update_right_now_message();

        echo "\n\t".'<br class="clear" /></div>';
        do_action( 'rightnow_end' );
        do_action( 'activity_box_end' );
}


?>
share|improve this answer
    
@MROSWELL -- I went through the file and information in detail however although the information and examples were very interesting none of the information on the link answered the question I am looking for an answer for. Please revise your answer if you know how to do it. –  NetConstructor.com Sep 30 '10 at 3:00
1  
I'm afraid I've only gotten you part-way there. I'll keep mulling it over, to see if we can get closer to a final answer. Or perhaps other answers will "bring it home." BTW, I was focusing on #2 (and #5) in your list of questions above. –  Marjorie Roswell Sep 30 '10 at 4:05
    
@mroswell -- I believe that for point 2 above it would remove the entire right now box when I only want to remove the areas within that as specified. Regarding point 5... yet, the link was defiantly interesting, thanks for sharing that. Please do let me know when you find any further information! –  NetConstructor.com Sep 30 '10 at 4:11
    
I guess my idea was to remove the original dashboard_right_now, and then replace it with a new my_dashboard_right_now, minus the offending parts. –  Marjorie Roswell Sep 30 '10 at 4:19
1  
@NetConstructor.com: I added the custom_dashboard_widgets example for the right_now_no_theme example.... could use some small tweaks, because the stylesheet's not quite right. But it works, that is, the theme button is no longer there. –  Marjorie Roswell Sep 30 '10 at 4:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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