There is code to connect stylesheets and scripts from header to footer for optimization.

function footer_enqueue_scripts(){ remove_action('wp_head','wp_print_scripts'); remove_action('wp_head','wp_print_head_scripts',9); remove_action('wp_head','wp_enqueue_scripts',1); add_action('wp_footer','wp_print_scripts',5); add_action('wp_footer','wp_enqueue_scripts',5); add_action('wp_footer','wp_print_head_scripts',5); } add_action('after_setup_theme','footer_enqueue_scripts'); 

Tell me how you can exclude from this transfer any one style registered with wp_enqueue_style("dfd_header_builder_front", $path);
those. so that not all styles are transferred to the footer.
Is it possible to somehow form an array and remove one style from it so that it remains in the header?

PS

 class WPBakeryShortCode_Dfd_User_Form extends WPBakeryShortCode { public function __construct($settings) { wp_enqueue_script("jquery-ui-datepicker"); wp_enqueue_style("dfd_datepicker", DFD_EXTENSIONS_PLUGIN_URL . "vc_custom/user_form/assets/css/datepicker/datepicker.min.css"); 

functions.php

 function dequeue_dfd() { wp_dequeue_style( 'dfd_datepicker' ); } add_action( 'wp_enqueue_scripts', 'dequeue_dfd', PHP_INT_MAX ); 
  • The question is clear, besides: МоТно Π»ΠΈ ΠΊΠ°ΠΊ-Ρ‚ΠΎ ΡΡ„ΠΎΡ€ΠΌΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ массив - KAGG Design
  • @KAGG Design, meaning the НазваниС скрипта (Ρ€Π°Π±ΠΎΡ‡Π΅Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅). Π‘Ρ‚Ρ€ΠΎΠΊΠ° Π² Π½ΠΈΠΆΠ½Π΅ΠΌ рСгистрС. НазваниС скрипта (Ρ€Π°Π±ΠΎΡ‡Π΅Π΅ Π½Π°Π·Π²Π°Π½ΠΈΠ΅). Π‘Ρ‚Ρ€ΠΎΠΊΠ° Π² Π½ΠΈΠΆΠ½Π΅ΠΌ рСгистрС. i.e. first argument to wp_enqueue_script , wp_enqueue_script ('newscript', get_template_directory_uri (). '/js/custom_script.js'); Well, if without this array of names, how can you then leave one style in the header , using the above code add_action('after_setup_theme','footer_enqueue_scripts'); ? - word
  • or the first argument in wp_enqueue_style НазваниС Ρ„Π°ΠΉΠ»Π° стилСй (ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€) , i.e. I'm talking about an array of such names - word

1 answer 1

To exclude only one style, you need the following code:

 function dequeue_dfd() { wp_dequeue_style( 'dfd_header_builder_front' ); } add_action( 'wp_enqueue_scripts', 'dequeue_dfd', PHP_INT_MAX ); 

It runs on the wp_enqueue_scripts event, with the lowest priority, guaranteed after all the other functions on this event. This ensures that the dfd_header_builder_front style dfd_header_builder_front already been added to the queue (otherwise you cannot remove it from the queue). The function in the example removes the required style.

  • But tell me, your code works, but not for all styles, the datepicker.min.css file is still connected. what could it be? Attached the code in question - word
  • There is no code with a tim file in the question. But the general rule is this: the script / style must be canceled by the handle (the first argument in wp_enqueue_script () / wp_enqueue_style () - KAGG Design