get_queried_object
退货NULL
连接到的函数内部wp_enqueue_scripts
当转到我的网站上不存在的类别URL时,执行操作挂钩。如果类别存在,则不会显示错误,我认为它不存在。
我需要它有条件地加载CSS文件,以便更好地模块化,不是在管理区域,而是为最终用户。
正确的方法是什么?
HTML中显示的错误:
注意:正在尝试在/var/www/html/wp-content/themes/custom-theme/functions中获取非对象的属性“term\\u-id”。php在线193
从第193行开始的代码:
if (get_queried_object()->term_id === 3 ||
(count(get_the_category()) > 0 && get_the_category()[0]->slug == \'arta\')) {
wp_enqueue_style( \'twentytwenty-style-2\', get_stylesheet_directory_uri() . \'/style-arta.css\', array(), $theme_version );
}