1

I developed a wordpress theme and it's working fine. Not until I discovered that some plugins are not working well with the theme due to the fact that the theme cannot import the styles and scripts of the plugins. So is there any code that can automatically enqueue any wordpress plugin script or style in my theme. I've read almost everything about wp_enqueue_script but I still can't get it working. Any help will be appreciated.

Thank you. Ossai Emmanuel C

1
  • You can add the necessary code to your theme's functions.php Commented Aug 18, 2016 at 19:14

2 Answers 2

1

Some plugins load their scripts into the footer instead of the <head>. Make sure your theme also contains this...

<?php
   /* Always have wp_footer() just before the closing </body>
    * tag of your theme, or you will break many plugins, which
    * generally use this hook to reference JavaScript files.
    */
    wp_footer();
?>
</body>
</html>

That's a direct quote from https://codex.wordpress.org/Function_Reference/wp_footer

Sign up to request clarification or add additional context in comments.

Comments

0

You probably need to call wp_head() at the bottom of the <head></head> section of your theme. Plugins hook onto the wp_head action to add their scripts and styles using wp_enqueue_script() and wp_enqueue_style(). wp_head() basically triggers the wp_head action. So just add wp_head() like this:

<html>
    <head>
        <!-- Your meta tags here -->
        <?php wp_head(); ?>
    </head>
    <body>
        <!-- Your html here -->
    </body>
</html>

Here is a reference on wp_head: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head

4 Comments

I have called wp_head() as you've said, but I still can't get it to work. Any help is welcomed.
@OssaiEmmanuelC hmm, it should work as long as you have wp_head. Did you check the source code of your website to confirm that the scripts and styles aren't there?
@OssaiEmmanuelC Also, maybe you could check your php error log. There could be an error that is preventing the scripts from getting enqueued.
I called wp_head() between the <head></head> tag and the wp_footer() at the footer before the </body> tag and it all went well! It now works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.