How does your plugin know to only display in wp-admin?

From a WPUniversity reader:

How does your plugin [SIDEKICK] know to only display in the lower right hand corner of any page contained in wp-admin?

As a plugin developer WordPress gives you the ability to hook into specific events in WordPress’ initialization. Those are called hooks. You can then specifically tell WordPress only execute this function call when a particular hook is called.

So for example if you want to only have your plugin start when the admin screens are showing you would write something like this

function load_custom_wp_admin_style() {
        wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );
        wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );

This code block will only load a specific style sheet when the admin_enqueue_scripts hook is processed at that specific time. This is how the entire WordPress architecture works, through filters and hooks and it’s what makes it possible for plugins to be able to process and modify data at any time.

WordPress as of 3.5 has over 1700 hooks, you can get a full list at http://adambrown.info/p/wp_hooks and learn more about hooks and filters at http://codex.wordpress.org/Plugin_API

About the author

Guest Contributor

Guest Contributor

WPUniversity Contributors help us make WordPress more approachable for non-developers. Want to get involved? Get all the details here.