Here are the code snippets from my “Amp Up Your Admin” talk which I’ve given at WordCamp Providence in 2014, WordCamp Miami in 2017, and at the Boston WordPress March 2017 Meetup.
View Slides (opens in a new tab)
Make Your Client Feel Welcome
Style the Login screen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php //Custom CSS for login page function login_css() { wp_enqueue_style('login-page', get_template_directory_uri() . '/css/login.css', false ); } // Change logo link from wordpress.org to your site’s url function login_url() { return home_url(); } // Change the alt text on the logo to show your site’s name function login_title() { return get_option('blogname'); } // calling it only on the login page add_action( 'login_enqueue_scripts', 'login_css', 10 ); add_filter( 'login_headerurl', 'login_url'); add_filter( 'login_headertitle', 'login_title'); ?> |
Promote Yourself / Provide Contact Info
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php // Custom Backend Footer function custom_admin_footer() { ?> <span id="footer-thankyou"> Developed by <a href="https://amandagiles.com" target="_blank">Amanda Giles</a>. For help with this site, please <a href="mailto:amanda@amandagiles.com">email me</a>. <span> <?php } // adding it to the admin area add_filter('admin_footer_text', 'custom_admin_footer'); ?> |
The above 2 snippets are from Eddie Machado’s Bones theme
Give them Information
Add columns to Listing pages
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php /* Adds new column headers to 'movies' post type */ function movies_add_new_columns($columns) { //Remove irrelevant columns unset($columns['author']); unset($columns['comments']); unset($columns['date']); $columns['release'] = 'Release Date'; return $columns; } add_filter('manage_edit-movies_columns', 'movies_add_new_columns'); /* Adds content to new columns for 'movies' post type */ function movies_manage_columns($column_name, $id) { global $post; switch ($column_name) { case 'release': echo get_post_meta( $post->ID , 'release-year' , true ); break; } } add_action('manage_movies_posts_custom_column', 'movies_manage_columns', 10, 2); ?> |
Make that information sortable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php /* Make new 'movies' columns sortable */ function movies_columns_sortable($columns) { $custom = array( 'release' => 'release', ); return wp_parse_args($custom, $columns); } add_filter('manage_edit-movies_sortable_columns', 'movies_columns_sortable'); /* Handle ordering for 'movies' columns */ function movies_columns_orderby( $vars ) { if ( isset( $vars['orderby'] ) ) { if ( 'release' == $vars['release'] ) $vars = array_merge( $vars, array( 'orderby' => 'meta_value_num', 'meta_key' => 'release-year') ); } return $vars; } add_filter( 'request', 'movies_columns_orderby' ); ?> |
Add a taxonomy filter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php /* Adds a filter in the Admin list pages on taxonomy for easier locating */ function movie_genre_filter_admin_content() { global $typenow; if( $typenow == "movies") { $taxonomies = array('genre'); } if (isset($taxonomies)) { foreach ($taxonomies as $tax_slug) { $tax_obj = get_taxonomy($tax_slug); $tax_name = $tax_obj->labels->name; $terms = get_terms($tax_slug); echo "<select name='$tax_slug' id='$tax_slug' class='postform'>"; echo "<option value=''>Show All $tax_name</option>"; foreach ($terms as $term) { $label = (isset($_GET[$tax_slug])) ? $_GET[$tax_slug] : ''; echo '<option value='. $term->slug, $label == $term->slug ? ' selected="selected"' : '','>' . $term->name .'</option>'; } } } } add_action( 'restrict_manage_posts', 'movie_genre_filter_admin_content' ); ?> |
Style Content Editor
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php // Apply styles to content editor to make it match the site function add_custom_editor_style() { //Looks for an 'editor-style.css' in your theme folder add_editor_style(); //Or call it with a custom file name if you choose //(helpful especially when keeping css in a subfolder) //add_editor_style('css/my-editor-style.css'); } add_action( 'admin_init', 'add_custom_editor_style' ); ?> |
Even use Google Fonts!
1 2 3 4 5 6 7 8 9 10 |
<?php /* Add Google Fonts to the Admin editor */ function add_google_fonts_admin_editor() { $font_url = 'https://fonts.googleapis.com/css?family=Dancing+Script:400,700'; //Encode Google Fonts URL if it contains commas add_editor_style( esc_url( $font_url ) ); } add_action( 'admin_init', 'add_google_fonts_admin_editor' ); ?> |
Add custom styles to editor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php /* * Adding new TinyMCE styles to editor * https://codex.wordpress.org/TinyMCE_Custom_Styles */ // Callback function to insert 'styleselect' into the $buttons array function add_tiny_mce_buttons( $buttons ) { array_unshift( $buttons, 'styleselect' ); return $buttons; } // Register our callback to the appropriate filter (2 means 2nd row) add_filter('mce_buttons_2', 'add_tiny_mce_buttons'); // Callback function to filter the Tiny MCE settings function tiny_mce_add_styles( $init_array ) { // Define the style_formats array $style_formats = array( // Each array child is a format with its own settings array( 'title' => 'Blue Title', 'block' => 'div', 'classes' => 'blue-title' ) ); // Insert the array, JSON ENCODED, into 'style_formats' $init_array['style_formats'] = json_encode( $style_formats ); return $init_array; } add_filter('tiny_mce_before_init','tiny_mce_add_styles' ); ?> |
Add Dashboard Widget
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php //Add widget to dashboard page function add_movies_dashboard_widgets() { wp_add_dashboard_widget('movies-widget', 'Recent Movies', 'movies_dashboard_widget'); } add_action('wp_dashboard_setup', 'add_movies_dashboard_widgets'); //Dashboard widget logic (can be anything!) function movies_dashboard_widget() { $args = array ( 'post_type' => 'movies', 'posts_per_page' => 5 ); $movies = new WP_Query( $args ); if($movies->have_posts()) : while($movies->have_posts()): $movies->the_post(); echo '<div style="margin-bottom: 10px;">'; $url = home_url() . "/wp-admin/post.php?post=" . get_the_id() . '&action=edit'; echo '<a href="' . $url . '">' . get_the_title() . '</a> - '; echo get_post_meta( get_the_id(), 'release-year' , true ) . '</div>'; endwhile; endif; } ?> |
Add Admin Bar Link
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php //Add Links to Admin Bar function movie_admin_bar_link( $wp_admin_bar ) { //Only add link for Admins if (current_user_can( 'manage_options' )) { $args = array( 'id' => 'movies-page', 'title' => 'Manage Movies', 'href' => home_url() . '/wp-admin/edit.php?post_type=movies', 'meta' => array( 'class' => 'movies-admin-link' ) ); $wp_admin_bar->add_node( $args ); } } add_action( 'admin_bar_menu', 'movie_admin_bar_link' ); ?> |
Add Help Page
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php // Add a page to WP Menu function add_help_admin_pages() { add_menu_page('Page Title', 'Menu Title', 'edit_posts', 'unique-menu-slug', 'admin_help_page_function'); } add_action('admin_menu', 'add_help_admin_pages'); //Define content for that page function admin_help_page_function() { //Can be anything you want! } ?> |
What do you think?