Adding Styles Css page on our plugin in Front or Admin Side

We need to initialize the function activation on loading the plugin path we have generally two option for loading the file content on initialization of plugin or initialization on admin section.

If we have object oriented concept on plugin we generally call the function on __constructor function.

public function __construct( $file )
/* Adding styles sheet page when my plugin activated for the front part */

/* Initialize on loading the admin part styles sheet */

/* Initialize when loading admin menu for the  admin part styles sheet */

add_action( ‘admin_menu’, ‘my_plugin_admin_menu’ );

function add_my_style_page(){
wp_enqueue_style(‘style-name’,  plugins_url(‘/css/style.css’,__FILE__));

function my_plugin_admin_menu() {

/* Register our plugin page */

$page = add_submenu_page( ‘edit.php’, __( ‘My Plugin’, ‘myPlugin’ ), __( ‘My Plugin’, ‘myPlugin’ ), ‘administrator’, __FILE__, ‘my_plugin_manage_menu’ );

/* Using registered $page handle to hook stylesheet loading */

add_action( ‘admin_print_styles-‘ . $page, ‘my_plugin_admin_styles’ );


function my_plugin_admin_styles() {

/* * It will be called only on your plugin admin page, enqueue our stylesheet here */

wp_enqueue_style( ‘myPluginStylesheet’ );


function my_plugin_manage_menu() {

/* Output our admin page */


Share this Story:
  • facebook
  • twitter
  • gplus

Leave a comment

Facebook Comment