Is it possible to hide certain fields in wp-admin. For

Is it possible to hide certain fields in wp-admin.

For example:
On the general options page I would like to hide the tagline option, the date and time format and the weekday starts on fields.

On a user's profile page I would like to hide the Personal Options (Visual editor and comment keyboard shortcuts).

I can't seem to hide them with CSS since the fields and labels have no classes or ID's.

Does anyone know if there is a function to hide these options?

  • Patrick

    Hi there @paaater

    Welcome to the forums, glad to have you aboard!

    They are a bit difficult to target with CSS with no IDs or classes. But it can be done with a bit of creative fiddling with nth-child():
    http://www.w3schools.com/cssref/sel_nth-child.asp

    However, depending on the plugins you have active on your site at any given time, the settings that actually occupy any specific positions may change. So that may not necessarily be the best option, unless you are certain that the layout of the screen where you want to hide stuff won't change.

  • paaater

    hey Patrick, thanks for the reply :slight_smile:

    For the 'screen options', 'help' and the 'admin color scheme' i already found functions. I was hoping there would be functions possible for the other options. I could hide them offcourse by editing the core admin files.. but that is never a good solution.

    Unfortunatly I don't thinks ntchild() will be the solution I am looking for either, since I want to hide multiple fields/options on multiple admin pages.

    If anyone has a suggestion or a tip to help me in the right direction it would be appreciated :slight_smile: Maybe build my own options page and hide the original one..?

    gr,
    Peter

  • Ash

    Hello @paaater

    Please try the following code:

    add_action( 'admin_head', 'hide_settings_field' );
    function hide_settings_field() {
    	if( ! is_super_admin() ){
    	?>
    	<script type="text/javascript">
    	jQuery(function($){
    		var data = [ 'Tagline', 'Date Format', 'Time Format', 'Week Starts On', 'Visual Editor', 'Admin Color Scheme', 'Keyboard Shortcuts' ],
    		    count = data.length;
    
    		for( var i = 0; i < count; i++ ){
    			if($( "th:contains('"+ data[i] +"')" ).length) $( "th:contains('"+ data[i] +"')" ).parent('tr').remove();
    		}
    	});
    	</script>
    	<?php
    	}
    }

    Add more text if you need in the data array.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • paaater

    Hi Ashok,

    you my friend, are amazing! Exactly what I was looking for :slight_smile:

    And thanks also for the mu-plugins tip! I knew that the plugins in this folder are the must use ones, and was already using the folder for some plugins.
    I did not know that a couple of functions in a php file would be enough to count as an actual plugin (but after your explanation and when I think about it, it actually makes a lot of sense). I am defenitly going to use that knowledge for other tweaks in my multisite network so I don't have to update every theme everytime I need a network wide change/adjustment.

    Thanks again!!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.