1

I have to customize the admin page where you edit the other pages "wp-admin/post.php". I have to add a lot of things, and delete others, change colors and add a custom menu to the top.

I don't know how to start searching for this. Are there any hooks, or funtions to change the HTML in the page editor?

I know how to add a CSS/JS file. But not how can I add HTML/PHP elements.

function admin_css() {
    wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/css/admin.css' );
}
add_action('admin_print_styles', 'admin_css' );

Thanks a lot

  • 2
    What does "change the HTML in the page editor" mean? – s_ha_dum May 26 '15 at 14:32
  • Add a custom menu to the top. – Marcos Aguayo May 26 '15 at 14:41
3
+50

There are functions available in WordPress to add/remove the elements. For instance to remove existing elements on WordPress backend page editor you can use remove_post_type_support function. Below is example usage:

<?php
add_action( 'init', 'my_remove_post_type_support', 10 );
function my_remove_post_type_support() {
    remove_post_type_support( 'post', 'custom-fields' );
}
?>

The above snippet will remove custom-fields box from edit page section on backend.

In similar manner you can add element using add_post_type_support() function. For instance 'Excerpt' element is not present by default for WordPress pages. You can add that using following code:

<?php
add_action('init', 'my_custom_init');
function my_custom_init() {
    add_post_type_support( 'page', 'excerpt' );
}
?>

To add custom elements other than what are supported by WordPress under add_post_type_support() function you will have to use add_meta_box(). You may refer to examples mentioned on codex and customize the code to suit your needs: https://codex.wordpress.org/Function_Reference/add_meta_box

About admin styles, WordPress by default provides different admin skins which can be checked under "Users > Your Profile". To add custom skin use following:

<?php
 wp_admin_css_color(
   'Soothing',
   __('Soothing'),
   admin_url("css/colors-classic.css"),
   array('#07273E', '#14568A', '#D54E21', '#2683AE')
 );
?>

Change the array of color codes as per your requirements.

I suggest you build a plugin for all above so that when the theme is changed you still retain that functionality. Also for custom admin skin you will need to provide the actual admin css file path in place of admin_url. The above code would show the new skin on option on backend but it won't apply the skin as the css file path won't render.

  • With add_post_type_support() I can add metaboxes but not my own custom HTML. Do you know how can I do this? – Marcos Aguayo May 29 '15 at 11:55
  • 1
    With add_post_type_support() you will be able to add predefined metaboxes which are allowed by WordPress. I am not sure what did you mean by custom HTML. Please provide more details. If you mean that you want to add metaboxes with custom input fields/options then you need to use add_meta_box() function. Please check second half portion of my original answer. – Prasad Nevase May 29 '15 at 14:03
  • Thanks a lot, it works. But what happends if I want to edit one metabox that comes by default? For example the box where you can save or publish the post. What if I want to delete "Visibility" and the date? – Marcos Aguayo May 29 '15 at 15:19
  • 1
    That seems to be already addressed here on stackexchange. wordpress.stackexchange.com/questions/36118/… – Prasad Nevase May 29 '15 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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