javascript - How do I add my own scripts to the add_action('wp_enqueue_scripts') function?

admin2025-06-04  0

The challenge is, when you connect your template to display a specific category, to completely clear the contents of a function wp_head().

Perfectly done by the function remove_all_actions('wp_head').

But after that I need to connect my own styles and scripts to it (previously cleaned).

Why doesn't this design work?

1) Delete all:

remove_all_actions('wp_head');

2) Add my own style file via a standard hook 'wp_enqueue_scripts':

add_action('wp_enqueue_scripts', function() {
  wp_enqueue_style('project-main', get_project_directory_url() .'/animals/styles.css', false, '0.0.0', 'all');
});

...has tried even so (, too, not works):

add_action('wp_head', function() {
  add_action('wp_enqueue_scripts', function() {
    wp_enqueue_style('project-main', get_project_directory_url() .'/animals/styles.css', false, '0.0.0', 'all');
  });
});

Please tell me how to clean the function wp_head() re-start adding your files via 'wp_enqueue_scripts'?

Thank you!

The challenge is, when you connect your template to display a specific category, to completely clear the contents of a function wp_head().

Perfectly done by the function remove_all_actions('wp_head').

But after that I need to connect my own styles and scripts to it (previously cleaned).

Why doesn't this design work?

1) Delete all:

remove_all_actions('wp_head');

2) Add my own style file via a standard hook 'wp_enqueue_scripts':

add_action('wp_enqueue_scripts', function() {
  wp_enqueue_style('project-main', get_project_directory_url() .'/animals/styles.css', false, '0.0.0', 'all');
});

...has tried even so (, too, not works):

add_action('wp_head', function() {
  add_action('wp_enqueue_scripts', function() {
    wp_enqueue_style('project-main', get_project_directory_url() .'/animals/styles.css', false, '0.0.0', 'all');
  });
});

Please tell me how to clean the function wp_head() re-start adding your files via 'wp_enqueue_scripts'?

Thank you!

Share Improve this question edited Jan 3, 2019 at 13:43 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Jan 3, 2019 at 13:36 Alexander BattAlexander Batt 1 1
  • You removed all of the actions from wp_head, one of those actions prints scripts and styles. You probably want to dequeue all other scripts and styles rather than disable the entire enqueue system. – Milo Commented Jan 3, 2019 at 16:25
Add a comment  | 

1 Answer 1

Reset to default 0

You removed all of the actions from wp_head, one of those actions prints scripts and styles. You probably want to dequeue all other scripts and styles rather than disable the entire enqueue system.

Yes

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749047928a315910.html

最新回复(0)