I have some code to register and conditionally enqueue a css file, but it is not running. It works fine when in functions.php or another snippets plugin. Disabling all plugins does not help.
add_action('init', 'register_custom_styles_scripts');
function register_custom_styles_scripts() {
wp_register_style( 'app-look', '/wp-content/themes/buddyboss-theme-child/assets/css/css-mobile-native-mimic.css' );
}
add_action( 'wp_enqueue_scripts', 'conditionally_enqueue_styles_scripts' );
function conditionally_enqueue_styles_scripts() {
global $wp;
if ( is_page('news-feed') || preg_match( '#^groups(/.+)[a-z0-9_-](/.+)?$#', $wp->request ) || preg_match( '#^members(/.+)[a-z0-9_-](/.+)?$#', $wp->request ) || preg_match( '#^forums(/.+)[a-z0-9_-](/.+)[a-z0-9_-](/.+)?$#', $wp->request ) ) {
function in_footer() {
wp_enqueue_style( 'app-look' );
}
add_action( 'wp_footer', 'in_footer');
}
}
I'm not sure why hidden link was added - the code I pasted starts with '/wp-content/'
Hi,
Thank you for contacting us and I'd be happy to assist.
When no priority number is provided with "add_action", '10' priority is used:
https://developer.wordpress.org/reference/functions/add_action/
But the way, the custom codes are added through Toolset, execution of "init" action is not possible with the priority lower than '20':
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#snippet-execution-timing
Can you please try by adding a priority value higher than '20', for example:
add_action('init', 'register_custom_styles_scripts', 100);
regards,
Waqar
Thanks very much! A priority of 100 worked.
My issue is resolved now. Thank you!