m (→Resources: Add Function links) |
m (Reverted edits by Mshar120 (talk) to last revision by Kolesnikovaalexandra) |
||
(30 intermediate revisions by 16 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Languages| |
||
+ | {{en|Creating Admin Themes}} |
||
+ | {{ja|Creating Admin Themes}} |
||
+ | {{ru|Создание темы для Админ-панели}} |
||
+ | }} |
||
+ | {{Copyedit}} |
||
+ | <!-- Dependencies on 'colors' CSS styles per example? Also, old admin themes are still marked here as examples. #zeitgeist doesn't exist anymore, etc. --> |
||
__TOC__ |
__TOC__ |
||
− | WordPress' flexible nature allows for almost every part of it to be easily changed. Creating a custom WordPress [[Administration Panels|Admin Panel]] Theme is no different. There are essentially two ways |
+ | WordPress' flexible nature allows for almost every part of it to be easily changed. Creating a custom WordPress [[Administration Panels|Admin Panel]] Theme is no different. There are essentially two ways to make a WordPress Admin theme: with a Plugin or by simply changing the [[CSS]]. The Plugin method is the easier of the two, allowing you to install WordPress Admin Themes quickly and easily. You literally "plug it in" and it works. |
− | If you are the creative type, we also have instructions to help you design your |
+ | If you are the creative type, we also have instructions to help you design your style sheet for the Administration Panels, and even how to turn your [[#Creating an Admin Theme Plugin|Admin Theme into a Plugin]] for easy distribution to the public. |
== Using Admin Theme Plugins == |
== Using Admin Theme Plugins == |
||
+ | [[File:wp-admin-theme.jpg|right|thumb]] |
||
− | [[Plugins|WordPress Plugins]] allow a user to easily add functionality to their blog without editing core WordPress files. There are several WordPress Plugins available that will allow you to use a WordPress Admin Theme with little or no fuss. Check the |
||
+ | |||
− | [[Using_Themes/Theme_List#Admin_Themes|List of Admin themes]] and follow their instructions to change the look of your Administration Panels. |
||
+ | [[Plugins|WordPress Plugins]] allow a user to easily add functionality to their blog without editing core WordPress files. There are several WordPress plugins available that will allow you to use a WordPress Admin Theme with little or no fuss. |
||
− | + | To do this, upload the Admin Theme Plugin to your plugins folder and then activate it on your [[Administration_Panels#Plugins_-_Add_Functionality_to_your_Blog|Plugin Panel]]. Simple and easy. |
|
+ | Other plugins, like [http://wordpress.org/extend/plugins/wp-admin-theme/ WP Admin Theme], allow you to change your layout on the fly, without needing to create your own plugin. |
||
− | [[Image:admin-themes-plugins.png|600px|Administration Theme Plugins]] |
||
+ | == Styling the Admin Theme == |
||
+ | [[Image:pinkhead.jpg|right|thumb|Pink Administration Theme]] The best way to design your own Administration Panel Theme is to make a plugin, even if you're never going to share the code with anyone else. As a plugin, the Admin Theme includes a function that will instruct WordPress to use a new stylesheet for displaying the Admin Panel. One of the distinct advantages of making a plugin is that if you ever want to revert to the default style, all you have to do is deactivate it. |
||
− | == Styling The Admin Theme == |
||
− | [[Image:tiger-admin-theme.png|right|thumb|Tiger Admin Theme]]Whether you are designing your own Administration Panel Theme or creating one for public distribution as a WordPress Plugin, the process is basically the same. As a Plugin, the Admin Theme includes a function that will instruct WordPress to use a new stylesheet for displaying the Admin Panel. A distinct advantage to making a plugin is that if you ever want to revert back to the default style, all you have to do is deactivate the plugin. If you are just making few changes and do not want to go through the hassle of creating your plugin, you might be better off just editing the CSS file directly. |
||
+ | You can also utilize the [[Must_Use_Plugins|mu-plugins]] folder for your plugin. |
||
− | ;Direct Editing :Make a backup copy of the <tt>wp-admin.css</tt> file from the <tt>wp-admin</tt> folder on your WordPress site. Then you can go in and make changes in the new <tt>wp-admin.css</tt> file with a backup, just in case. |
||
===The Admin Style Sheet=== |
===The Admin Style Sheet=== |
||
− | [[Image: |
+ | [[Image:bluehead.jpg||right|thumb|Blue Administration Theme]]The default Admin Theme style sheet is very complex, covering all aspects of the Administration Panels thoroughly. Not all the parts and pieces may need to be changed to recreate your Admin Theme. You can look at the files stored in <code>/wp-admin/css</code> to see all the style components that go into the admin dashboard. |
+ | |||
Here is a partial list of the important style references used in the Administration Panels. Per CSS web standards, <tt>#</tt> denotes a style ID and <tt>.</tt> denotes a style class. |
Here is a partial list of the important style references used in the Administration Panels. Per CSS web standards, <tt>#</tt> denotes a style ID and <tt>.</tt> denotes a style class. |
||
Line 34: | Line 43: | ||
; <tt>.wrap h2</tt> :Individual Page headers for the various subpanels, like '''General Options'''. |
; <tt>.wrap h2</tt> :Individual Page headers for the various subpanels, like '''General Options'''. |
||
− | The changes you make |
+ | The changes you make can be major or minor. For instance, you can change the background color, add a background image to different sections, change the font, or even just do a minor color or design change to the [[Coloured_Quicktags|Quicktag buttons]]. Feel free to use your imagination and create whatever effect you want. |
=== Creating an Admin Theme Plugin === |
=== Creating an Admin Theme Plugin === |
||
+ | Admin theme plugins can be used to change the header or footer of admin pages in different ways. |
||
− | To create an Admin Theme Plugin, it will need to be easily installed with little effort by the user, and easily uninstalled or deactivated, returning the [[Administration Panels]] to their original state. |
||
+ | |||
+ | One benefit of admin theme plugins is that they can be easily installed with little effort by the user, and just as easily uninstalled or deactivated, returning the [[Administration Panels]] to their original state. |
||
We begin by telling WordPress to link to a new style sheet. |
We begin by telling WordPress to link to a new style sheet. |
||
Line 46: | Line 57: | ||
<pre> |
<pre> |
||
<?php |
<?php |
||
− | /* |
||
− | Plugin Name: Blue Steel Theme |
||
− | Plugin URI: http://example.com/blue-steel-admin-theme |
||
− | Description: Blue Steel WordPress Admin Theme - Upload and Activate. |
||
− | Author: Mr. WordPress |
||
− | Version: 1.0 |
||
− | Author URI: http://example.com |
||
− | */ |
||
− | ?> |
||
− | </pre> |
||
− | |||
− | This is the "header" of the style sheet and provides information about the plugin to be viewed on the [[Administration_Panels#Plugins_-_Add_Functionality_to_your_Blog|Plugin Panel]]. It provides the name, [[Glossary#URI_and_URL|URI]] of the plugin, the description, author, and version. |
||
− | |||
− | Create a folder on your computer, per this example, called <tt>blue-steel</tt>. Save this file inside of the folder and call it <tt>blue-steel.php</tt>. When you are ready, upload the entire folder to your plugin folder on your website at <tt>/wp-content/plugins/</tt>. This folder should be at <tt>/wp-content/plugins/blue-steel/</tt> and the plugin file should be at <tt>/wp-content/plugins/blue-steel/blue-steel.php</tt>. |
||
− | |||
− | To make this plugin call a new style sheet for the Administration Panels, we need to create a function that will add the style sheet to the <tt>head</tt> of the Admin Panel's <tt>header</tt>. This is no different than adding a link to a style sheet in all web pages. It will look something like this when the page is generated: |
||
− | |||
− | <pre><link rel="stylesheet" type="text/css" |
||
− | href="http://example.com/wp-content/plugins/blue-steel/wp-admin.css"></pre> |
||
− | |||
− | With your plugin, you will want to detect where the user has installed WordPress, so that you know where the rest of your Theme is located. You can use the <tt>get_option()</tt> (Deprecated 2.1: <tt>get_settings()</tt>) function for that. This makes your plugin flexible and portable. Here is how we would create the stylesheet <tt>link</tt> shown above: |
||
− | <pre><?php |
||
/* |
/* |
||
− | Plugin Name: |
+ | Plugin Name: My Admin Theme |
− | Plugin URI: http://example.com/ |
+ | Plugin URI: http://example.com/my-crazy-admin-theme |
− | Description: |
+ | Description: My WordPress Admin Theme - Upload and Activate. |
− | Author: |
+ | Author: Ms. WordPress |
Version: 1.0 |
Version: 1.0 |
||
Author URI: http://example.com |
Author URI: http://example.com |
||
*/ |
*/ |
||
− | function |
+ | function my_admin_theme_style() { |
+ | wp_enqueue_style('my-admin-theme', plugins_url('wp-admin.css', __FILE__)); |
||
− | $url = get_option('siteurl'); |
||
− | $url = $url . '/wp-content/plugins/blue-steel/wp-admin.css'; |
||
− | echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />'; |
||
} |
} |
||
+ | add_action('admin_enqueue_scripts', 'my_admin_theme_style'); |
||
+ | add_action('login_enqueue_scripts', 'my_admin_theme_style'); |
||
− | ?> |
+ | ?> |
+ | </pre> |
||
+ | This plugin simply allows you to customize the CSS of the admin dashboard via a file called <tt>wp-admin.css</tt> in your plugin folder. |
||
− | Before we get to the actual styles, you need to add an action with the [[Plugin_API#Adding_Actions|Plugin API]]. Actions allow for plugins to "hook" into functions and features of the program. For Admin Themes, you want to hook into the <tt>admin_head</tt> (called in the <tt><head></tt>) of the Administration Panel with <tt>add_action()</tt>: |
||
+ | |||
+ | If you wanted to change the <tt>#wphead</tt> format to look blue (like in the above image), then you would add in: |
||
<pre> |
<pre> |
||
+ | #wphead { |
||
− | function mr_blue_steel() { |
||
+ | border-bottom: MidnightBlue 1px solid; |
||
− | $url = get_option('siteurl'); |
||
+ | background-color: #E4F0FE!important; |
||
− | $url = $url . '/wp-content/plugins/blue-steel/wp-admin.css'; |
||
+ | background: -moz-linear-gradient(bottom,#E4F0FE,#B0C4DE); |
||
− | echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />'; |
||
+ | background: -webkit-gradient(linear,left bottom,left top,from(#E4F0FE),to(#B0C4DE)); |
||
} |
} |
||
+ | </pre> |
||
− | add_action('admin_head', 'mr_blue_steel'); |
||
+ | In addition to using the <tt>admin_head</tt> Plugin API hook for stylesheets, you also have the option to add a function that allows you to add content to the <tt>admin_footer</tt>. For example, you might want to put a notice about the theme in the footer. Here is how to add it to your plugin: |
||
− | ?></pre> |
||
− | |||
− | In addition to the <tt>admin_head</tt> Plugin API hook, you can also optionally add a function to add content to the <tt>admin_footer</tt>. For example, you might want to put a notice about the theme in the footer. Here is how to add it to your plugin: |
||
<pre> |
<pre> |
||
− | function |
+ | function my_crazy_admin_footer() { |
− | echo 'This theme was made by <a href="http://example.com"> |
+ | echo '<p>This theme was made by <a href="http://example.com">Ms. WordPress</a>.</p>'; |
} |
} |
||
− | add_action('admin_footer', ' |
+ | add_action('admin_footer', 'my_crazy_admin_footer'); |
</pre> |
</pre> |
||
+ | Which looks like this: |
||
− | Save the plugin and upload it to your site. Select it from the Plugins Panel and see if anything about <tt>blue-steel</tt> appears. If it does, you are on the right track! |
||
+ | [[Image:footer.jpg|center]] |
||
+ | Save the plugin and upload it to your site. Select it from the Plugins Panel and see if anything about <tt>My Admin Theme</tt> appears. If it does, you are on the right track! |
||
− | == Change Log-In page's style == |
||
+ | Another way would be to use filters instead of actions: |
||
− | If you would like to change your Log-In page's style with your <tt>wp-admin.css</tt> file you must be use the <tt>wp_admin_css</tt> function. Create a plugin that contains these lines: |
||
<pre> |
<pre> |
||
+ | add_filter('admin_footer_text', 'left_admin_footer_text_output'); //left side |
||
− | function my_wp_admin_css() { |
||
+ | function left_admin_footer_text_output($text) { |
||
− | echo '<link rel="stylesheet" href="/wp-content/plugins/blue-steel/wp-admin.css" type="text/css" />'; |
||
+ | $text = 'How much wood would a woodchuck chuck?'; |
||
+ | return $text; |
||
+ | } |
||
+ | |||
+ | add_filter('update_footer', 'right_admin_footer_text_output', 11); //right side |
||
+ | function right_admin_footer_text_output($text) { |
||
+ | $text = 'That\'s purely hypothetical.'; |
||
+ | return $text; |
||
} |
} |
||
− | |||
− | add_action('wp_admin_css','my_wp_admin_css'); |
||
</pre> |
</pre> |
||
+ | Which looks like this, totally replacing the footer: |
||
− | This plugin overrides the original function, and displays only your stylesheet in the admin page's header. You use the <tt>.login</tt> and the <tt>#login</tt> element in the CSS file to change the page's style. |
||
+ | [[Image:footer-filter.jpg|center]] |
||
− | If you use this plugin you don't need to use the <tt>admin_head</tt> function that you read before! |
||
+ | Source: [http://wpglee.com/2011/02/change-admin-footer-text/ WP Glee] |
||
− | Alternatively, if you don't want to override the default wp-admin.css stylesheet for the overall admin screen, you can use the <tt>login_head</tt> function to add a style sheet solely to your log-in page. To get this working, copy the login.css file from <tt>/wp-admin/css/</tt> you can append the following to the original plug-in you've created. |
||
+ | == Change Log-In page's style == |
||
− | <pre> |
||
− | function wp_blue_steel_login() { |
||
− | echo '<link rel="stylesheet" type="text/css" href="' . get_option('siteurl') . '/wp-content/plugins/blue-steel/login.css" />'."\n"; |
||
− | } |
||
+ | You can use the [[Plugin_API/Action_Reference/login_head|<tt>login_head</tt>]] action to add a style sheet to your log-in page. To get this working, copy the <tt>login.css</tt> file from <tt>/wp-admin/css/</tt> you can append the following to the original plug-in you've created. |
||
− | add_action('login_head', 'wp_admin_login_css'); |
||
− | </pre> |
||
− | The <tt>wp_admin_css</tt> function also displays some other CSS file so you should add some other lines to this plugin. You can find these stylesheet files in the <tt>wp-admin</tt> folder, and the <tt>/wp-admin/css/</tt> maps (For example: <tt>upload.css</tt>). |
||
− | |||
− | If you would like to use the original style: |
||
<pre> |
<pre> |
||
+ | function my_login_css() { |
||
− | echo '<link rel="stylesheet" href="/wp-admin/css/upload.css" type="text/css" />'; |
||
+ | echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('login.css ', __FILE__). '">'; |
||
− | </pre> |
||
− | |||
− | If you would like to use your style: |
||
− | <pre> |
||
− | echo '<link rel="stylesheet" href="/wp-content/plugins/blue-steel/upload.css" type="text/css" />'; |
||
− | </pre> |
||
− | |||
− | In the end: |
||
− | <pre> |
||
− | <?php |
||
− | /* |
||
− | Plugin Name: Blue Steel Theme |
||
− | Plugin URI: http://example.com/blue-steel-admin-theme |
||
− | Description: Blue Steel WordPress Admin Theme - Upload and Activate. |
||
− | Author: Mr. WordPress |
||
− | Version: 1.0 |
||
− | Author URI: http://example.com |
||
− | */ |
||
− | |||
− | function my_wp_admin_css() { |
||
− | echo ' |
||
− | // use the "blue-steel" style |
||
− | <link rel="stylesheet" href="/wp-content/plugins/blue-steel/wp-admin.css" type="text/css" /> |
||
− | // use the original style |
||
− | <link rel="stylesheet" href="/wp-admin/css/upload.css" type="text/css" /> |
||
− | '; |
||
} |
} |
||
− | add_action(' |
+ | add_action('login_head', 'my_login_css'); |
− | ?> |
||
</pre> |
</pre> |
||
+ | == Advanced CSS Styles == |
||
− | These plugins don't work with the <tt>install.css</tt> file and the <tt>"rtl"</tt> files. If you would like to use the <tt>rtl</tt> files, please look at how the <tt>wp_admin_css</tt> function works in the <tt>wp_include/general-template.php</tt> file. |
||
− | |||
− | === Advanced CSS Styles === |
||
[[Image:admin-rounded-corners.png|right|thumbnail|Rounded Corners]] |
[[Image:admin-rounded-corners.png|right|thumbnail|Rounded Corners]] |
||
Sometimes there are places where CSS just cannot achieve the look you want without making modifications to the HTML of the Administration Panels. |
Sometimes there are places where CSS just cannot achieve the look you want without making modifications to the HTML of the Administration Panels. |
||
− | A popular CSS style is to create rounded corners on "boxes" of content. The technique involves adding divisions or ''wrappers'' to the HTML architecture |
+ | A popular CSS style is to create rounded corners on "boxes" of content. The technique involves adding divisions or ''wrappers'' to the HTML architecture to achieve the effect. Since we do not want to get into the core Administration Panels to make these changes, which will disappear with the next upgrade, you can use the DOM (Document Object Model). The DOM is a way of dynamically accessing and updating content, structure, and style of documents. |
In this example, using the [http://www.456bereastreet.com/archive/200609/transparent_custom_corners_and_borders_version_2/ Transparent Rounded Corners] effect from 456 Berea Street, you can add the Javascript provided on the site to your Admin Theme Plugin, without editing the WordPress source. |
In this example, using the [http://www.456bereastreet.com/archive/200609/transparent_custom_corners_and_borders_version_2/ Transparent Rounded Corners] effect from 456 Berea Street, you can add the Javascript provided on the site to your Admin Theme Plugin, without editing the WordPress source. |
||
Line 200: | Line 163: | ||
== Resources == |
== Resources == |
||
− | * [[Using_Themes/Theme_List#Admin_Themes|List of Admin themes]] |
||
* [[Function_Reference/get_option|get_option]] |
* [[Function_Reference/get_option|get_option]] |
||
* [[Function_Reference/get_settings|get_settings]] (Deprecated 2.1) |
* [[Function_Reference/get_settings|get_settings]] (Deprecated 2.1) |
||
Line 208: | Line 170: | ||
* [[Blog_Design_and_Layout#WordPress_and_CSS|WordPress and CSS]] |
* [[Blog_Design_and_Layout#WordPress_and_CSS|WordPress and CSS]] |
||
− | [[Category: |
+ | [[Category:About Codex]] |
− | [[Category:Design and Layout]] |
||
− | {{Copyedit}} |
Languages: English • Admin Themes 日本語 Русский • (Add your language)
WordPress' flexible nature allows for almost every part of it to be easily changed. Creating a custom WordPress Admin Panel Theme is no different. There are essentially two ways to make a WordPress Admin theme: with a Plugin or by simply changing the CSS. The Plugin method is the easier of the two, allowing you to install WordPress Admin Themes quickly and easily. You literally "plug it in" and it works.
If you are the creative type, we also have instructions to help you design your style sheet for the Administration Panels, and even how to turn your Admin Theme into a Plugin for easy distribution to the public.
WordPress Plugins allow a user to easily add functionality to their blog without editing core WordPress files. There are several WordPress plugins available that will allow you to use a WordPress Admin Theme with little or no fuss.
To do this, upload the Admin Theme Plugin to your plugins folder and then activate it on your Plugin Panel. Simple and easy.
Other plugins, like WP Admin Theme, allow you to change your layout on the fly, without needing to create your own plugin.
You can also utilize the mu-plugins folder for your plugin.
/wp-admin/css
to see all the style components that go into the admin dashboard.
Here is a partial list of the important style references used in the Administration Panels. Per CSS web standards, # denotes a style ID and . denotes a style class.
The changes you make can be major or minor. For instance, you can change the background color, add a background image to different sections, change the font, or even just do a minor color or design change to the Quicktag buttons. Feel free to use your imagination and create whatever effect you want.
Admin theme plugins can be used to change the header or footer of admin pages in different ways.
One benefit of admin theme plugins is that they can be easily installed with little effort by the user, and just as easily uninstalled or deactivated, returning the Administration Panels to their original state.
We begin by telling WordPress to link to a new style sheet.
In a text editor, in a new document, put the following:
<?php /* Plugin Name: My Admin Theme Plugin URI: http://example.com/my-crazy-admin-theme Description: My WordPress Admin Theme - Upload and Activate. Author: Ms. WordPress Version: 1.0 Author URI: http://example.com */ function my_admin_theme_style() { wp_enqueue_style('my-admin-theme', plugins_url('wp-admin.css', __FILE__)); } add_action('admin_enqueue_scripts', 'my_admin_theme_style'); add_action('login_enqueue_scripts', 'my_admin_theme_style'); ?>
This plugin simply allows you to customize the CSS of the admin dashboard via a file called wp-admin.css in your plugin folder.
If you wanted to change the #wphead format to look blue (like in the above image), then you would add in:
#wphead { border-bottom: MidnightBlue 1px solid; background-color: #E4F0FE!important; background: -moz-linear-gradient(bottom,#E4F0FE,#B0C4DE); background: -webkit-gradient(linear,left bottom,left top,from(#E4F0FE),to(#B0C4DE)); }
In addition to using the admin_head Plugin API hook for stylesheets, you also have the option to add a function that allows you to add content to the admin_footer. For example, you might want to put a notice about the theme in the footer. Here is how to add it to your plugin:
function my_crazy_admin_footer() { echo '<p>This theme was made by <a href="http://example.com">Ms. WordPress</a>.</p>'; } add_action('admin_footer', 'my_crazy_admin_footer');
Which looks like this:
Save the plugin and upload it to your site. Select it from the Plugins Panel and see if anything about My Admin Theme appears. If it does, you are on the right track!
Another way would be to use filters instead of actions:
add_filter('admin_footer_text', 'left_admin_footer_text_output'); //left side function left_admin_footer_text_output($text) { $text = 'How much wood would a woodchuck chuck?'; return $text; } add_filter('update_footer', 'right_admin_footer_text_output', 11); //right side function right_admin_footer_text_output($text) { $text = 'That\'s purely hypothetical.'; return $text; }
Which looks like this, totally replacing the footer:
Source: WP Glee
You can use the login_head action to add a style sheet to your log-in page. To get this working, copy the login.css file from /wp-admin/css/ you can append the following to the original plug-in you've created.
function my_login_css() { echo '<link rel="stylesheet" type="text/css" href="' .plugins_url('login.css ', __FILE__). '">'; } add_action('login_head', 'my_login_css');
Sometimes there are places where CSS just cannot achieve the look you want without making modifications to the HTML of the Administration Panels.
A popular CSS style is to create rounded corners on "boxes" of content. The technique involves adding divisions or wrappers to the HTML architecture to achieve the effect. Since we do not want to get into the core Administration Panels to make these changes, which will disappear with the next upgrade, you can use the DOM (Document Object Model). The DOM is a way of dynamically accessing and updating content, structure, and style of documents.
In this example, using the Transparent Rounded Corners effect from 456 Berea Street, you can add the Javascript provided on the site to your Admin Theme Plugin, without editing the WordPress source.
Download the script and save it to your blue-steel folder as javascript.js. Change the mr_blue_steel() function to:
function mr_blue_steel() { $url = get_option('siteurl'); $dir = $url . '/wp-content/plugins/blue-steel/'; echo '<link rel="stylesheet" type="text/css" href="' . $dir . 'wp-admin.css" />'; echo '<script type="text/javascript" src="' . $dir .'javascript.js"></script>'; }
This script uses a single "hook" (cbb) to create many divisions around the container. For this to work, open the Javascript file and change all references of cbb to wrap to match the wp-admin.css standard style references.