简体   繁体   中英

use bloginfo('template_directory') in functions.php

I want to give my wordpress dashboard custom css styles by using external css file in my theme. This is my code:

<?php
// Custom Dashboard Styles by Loading assets/css/admin.css
function filmview_admin_css() {
    echo '<link rel="stylesheet" href="bloginfo('template_directory')/assets/css/admin.css" type="text/css" media="all" />';
}
add_action('admin_head', 'filmview_admin_css');
?>

You can't use bloginfo() and echo at the same time because bloginfo() is already outputting a string.

Anyway, I suggest you to use get_template_directory_uri() , get_theme_file_uri() or get_parent_theme_file_uri() instead because those functions are meant to be used on functions.php for this kind of purposes.

Also, to enqueue styles or scripts, you should use WordPress built in functions like wp_enqueue_style() and hooks like admin_enqueue_scripts :

function filmview_admin_css() {
    wp_enqueue_style( 'custom_wp_admin_css', get_template_directory_uri() . '/assets/css/admin.css' );
}
add_action( 'admin_enqueue_scripts', 'filmview_admin_css' );

Please see this thread https://wordpress.stackexchange.com/questions/41207/how-do-i-enqueue-styles-scripts-on-certain-wp-admin-pages .

In general you could use:

function admin_custom_css() { wp_enqueue_style( 'stylesheet_name', 'stylesheet.css'); } add_action('admin_init', 'admin_custom_css' );

Don't hardcode things like <link rel="... as it is bad practice and WordPress can do it all for you in a coherent way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM