Home > Mobile >  Linking the PHP file to the CSS file
Linking the PHP file to the CSS file

Time:01-06

I want to style the WordPress admin area. For this purpose, I have copied the following code in the function file and started styling it:

 function custom_css()
    
    { echo '<style>
    
    .widefat {
        width: 1700px !important;
        max-width: 1700px !important;
    }
    
    </style>'; }
 add_action('admin_head','custom_css');

this way, the function file becomes very crowded, and that's why I want to style it in a separate CSS file; How can I enter the link of my style.css file in the code above?

I have used this code but it did not work:

{ echo include ("/style.css"); }

CodePudding user response:

I found the answer to my question. The answer is as follows:

       function custom_css()
            
            { echo 
wp_enqueue_style( 'style', get_template_directory_uri() . '/style.css', array(), '4.0.0' ); }

add_action('admin_head','custom_css');

CodePudding user response:

/* admin_enqueue_scripts is the proper hook to use when enqueuing scripts and styles that are meant to be used in the administration panel. Despite the name, it is used for enqueuing both scripts and styles. */


Enqueue a custom stylesheet in the admin

Sometimes you want to load a set of CSS and/or Javascript documents to all admin pages. You can do this from within your plugin or from your themes function file:

/**
 * Register and enqueue a custom stylesheet in the WordPress admin.
 */

// get_template_directory_uri() -> Retrieves template directory URI for the active theme.

function wpdocs_enqueue_custom_admin_style() {

        // loading css
        
        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' ); // Enqueue a style.
        
        // loading js
        
        wp_register_script( 'custom_wp_admin_js', get_template_directory_uri().'/admin-script.js',             array('jquery-core'),false, true );
        
        wp_enqueue_script( 'custom_wp_admin_js' ); // Enqueue a script.
}

add_action( 'admin_enqueue_scripts', 'wpdocs_enqueue_custom_admin_style' );

  • Related