Saltar navegación

[Resuelto] Custom Code Snippet not running

This support ticket is created hace 3 años, 3 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Etiquetado: 

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por NickC8880 hace 3 años, 3 meses.

Asistido por: Waqar.

Autor
Mensajes
#2173451

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');
   } 
}
#2173453

I'm not sure why enlace oculto was added - the code I pasted starts with '/wp-content/'

#2173641

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

#2174019

Thanks very much! A priority of 100 worked.

#2174035

My issue is resolved now. Thank you!