0

I am following a tutorial in an attempt to create a custom theme on Wordpress. I created my functions.php file in my theme folder, and am attempting to use the Wordpress function 'wp_enqueue_style()' from functions.php. 'wp_enqueue_style()' is not working or populating on my text-editor, in fact, none of the functions starting in 'wp_' are working in my functions.php.

I checked the source of the wp_enqueue_style() function, which is 'includes/function.wp-styles', and it IS included in my directory, and I also tried using require_once('path to includes/function.wp-styles'); to link to that file from within functions.php.

I am totally clueless at this point...thank you in advance for your help.

1

check your header.php it should contain <?php wp_head(); ?> before the closing </head> tag.

check your footer.php it should contain <?php wp_footer(); ?> before the closing </body> tag.

You also need to hook your function to wp_enqueue_scripts action hook and then add wp_enqueue_script() and wp_enqueue_style() inside that function. e.g;

function add_theme_scripts_styles() {
    wp_enqueue_style( 'style-name', 'path_to_the_style.css' );
    wp_enqueue_script( 'script-name', 'path_to_the_script.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts_styles' );
  • thanks for the response. I had not done that yet but it did not help. can you think of any other reason why I wouldn't be able to use the wp_enqueue_style() function? – CandyPaintedRIMS Aug 18 '16 at 22:05
  • i mean check your header.php file there you should have <?php wp_head(); ?> before closing </head> and also check your footer.php file you should also have <?php wp_footer(); ?> function before </body> – Aamer Shahzad Aug 18 '16 at 22:16
  • missing wp_head() and wp_footer() does not enqueue the scripts and styles. – Aamer Shahzad Aug 18 '16 at 22:17
  • you also need to hook your function to wp_enqueue_scripts and then add wp_enqueue_script() and wp_enqueue_style() inside that function. e.g; function add_theme_scripts_styles() { wp_enqueue_style( 'style-name', 'path_to_the_style.css' ); wp_enqueue_script( 'script-name', 'path_to_the_script.js', array('jquery'), '1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'add_theme_scripts_styles' ); – Aamer Shahzad Aug 18 '16 at 22:20
  • welcome, please cast your vote :-) – Aamer Shahzad Aug 18 '16 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.