0

At this moment I use functions as described in the "Theme handbook" from the WordPress site. The problem is that the stylesheet is loading on the backend pages too and it affects the layout of the backend pages. This behavior is not wanted.

The code I use to load the stylesheet -> https://pastebin.com/rAMZSu3u

Does anyone know a way/method to load the stylesheet only on the frontend so the wp-admin backend does not get affected?

Note: The CSS is compiled with scssphp when the $dev variable is set to true.

  • The Codeshare page is empty. Please place the code here. – Max Yudin Apr 22 '17 at 14:48
  • I changed it to Pastebin. The question has been updated – Dany Apr 22 '17 at 14:49
0

There is a conditional tag is_admin() which checks are you in the Administration Panel or Frontend. So,

if( !is_admin() ) {
    wp_enqueue_style(
        'css-minified',
        get_stylesheet_directory_uri() . DIRECTORY_SEPARATOR . 'style.css',
        [],
        null,
        'all'
    );
    wp_enqueue_style(
        'font-awesome',
        'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',
        [],
        null,
        'all'
    );
}

See is_admin().

1

Your styles should be enqueued on the wp_enqueue_scripts hook for the public side or admin_enqueue_scripts for the admin side.

//* Enqueue public scripts and style
function wpse_264511_wp_enqueue_scripts {
    wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' );
}
add_action( 'wp_enqueue_scripts', 'wpse_264511_wp_enqueue_scripts' );

//* Enqueue admin scripts and style
function wpse_264511_admin_enqueue_scripts {
    wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' );
}
add_action( 'admin_enqueue_scripts', 'wpse_264511_admin_enqueue_scripts' );

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.