get_queried_object
returns NULL
inside a function hooked to wp_enqueue_scripts
action hook when going to an nonexistent category URL on my website. If the category exists, the error is not shown and I think it does not exist.
I need it to conditionally load a CSS file for better modularization, not in the admin area but for the end-user.
What is the correct way to do this?
The error shown in the HTML:
Notice: Trying to get property 'term_id' of non-object in /var/www/html/wp-content/themes/custom-theme/functions.php on line 193
The code starting at line 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 );
}