WordPress子主题自定义前台和后台css引用

2023-09-11
825次阅读
没有评论

get_theme_root_uri() 是 WordPress 中的一个函数,用于获取当前主题的根目录的URI(Uniform Resource Identifier)。这个函数返回当前主题的根目录的URL,通常用于引用主题中的资源文件(例如CSS、JavaScript等)或者生成主题相关的链接。

以下是 get_theme_root_uri() 函数的用法:

$theme_root_uri = get_theme_root_uri();

这将返回当前激活的主题的根目录的URI,例如:http://example.com/wp-content/themes/your-theme-name,其中 “your-theme-name” 是当前激活的主题的文件夹名称。

你可以使用这个URI来构建主题相关资源的URL,例如:

$css_url = get_theme_root_uri() . '/your-css-folder/style.css';
$js_url = get_theme_root_uri() . '/your-js-folder/script.js';

这样你就可以获得主题中的CSS和JavaScript文件的URL,然后将它们添加到你的WordPress主题中。

请注意,get_theme_root_uri() 函数只返回主题的根目录URI,而不包括主题子目录的URI。如果你需要获取子目录的URI,你可以将子目录名称附加到返回的URI上,就像上面的示例中所做的那样。

后台自定义CSS

function mytheme_enqueue_options_style() {
    wp_enqueue_style( 'mytheme-options-style', get_theme_root_uri() . '/ylface-child/style-admin.css' );
}
add_action( 'admin_enqueue_scripts', 'mytheme_enqueue_options_style' );

前台自定义CSS

function additional_stylesheets()
{
    wp_register_style('custom', get_theme_root_uri() . '/ylface-child/style-web.css');
    wp_enqueue_style('custom');
}
add_action('wp_enqueue_scripts', 'additional_stylesheets', 999);

正文完
要饭中,多少给点吧(支付宝)
post-qrcode
 
评论(没有评论)
验证码