0
0
Wordpressframework~20 mins

Enqueuing styles and scripts in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Enqueue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output when this WordPress enqueue function runs?
Consider this code snippet in a theme's functions.php file. What will happen when the page loads?
Wordpress
<?php
function load_my_styles() {
  wp_enqueue_style('my-style', get_template_directory_uri() . '/css/style.css');
}
add_action('wp_enqueue_scripts', 'load_my_styles');
?>
AThe style.css file will load but only if the user is logged in.
BThe style.css file will not load because the hook is incorrect.
CThe style.css file will load but only in the admin dashboard, not the front end.
DThe style.css file located in the theme's css folder will be loaded in the page header.
Attempts:
2 left
💡 Hint
Think about the correct hook to load styles on the front end.
📝 Syntax
intermediate
2:00remaining
Which option correctly enqueues a JavaScript file with jQuery dependency?
You want to enqueue a JavaScript file named 'custom.js' located in your theme's js folder. It depends on jQuery. Which code snippet is correct?
Awp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', 'jquery', null, true);
Bwp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true);
Cwp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array(), true);
Dwp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array('jquery'), false, true);
Attempts:
2 left
💡 Hint
Check the third parameter for dependencies and the last for loading in footer.
🔧 Debug
advanced
2:00remaining
Why does this enqueue function cause a fatal error?
Look at this code snippet. Why will it cause a fatal error when WordPress loads?
Wordpress
<?php
function load_scripts() {
  wp_enqueue_script('main-js', get_template_directory_uri() . '/js/main.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'load_scripts');
?>
AMissing closing parenthesis in wp_enqueue_script causes a syntax error.
BThe hook 'wp_enqueue_scripts' is misspelled causing the function not to run.
CThe dependency array is empty, so jQuery is not loaded causing an error.
DThe function name conflicts with a WordPress core function causing a fatal error.
Attempts:
2 left
💡 Hint
Check the parentheses and commas carefully.
state_output
advanced
2:00remaining
What is the effect of this code on script loading order?
Given this code, what will be the order of script loading on the page?
Wordpress
<?php
function load_scripts() {
  wp_enqueue_script('script-one', get_template_directory_uri() . '/js/one.js', array(), null, true);
  wp_enqueue_script('script-two', get_template_directory_uri() . '/js/two.js', array('script-one'), null, true);
  wp_enqueue_script('script-three', get_template_directory_uri() . '/js/three.js', array('script-two'), null, true);
}
add_action('wp_enqueue_scripts', 'load_scripts');
?>
AScripts will load in the order: one.js, two.js, three.js in the footer.
BScripts will load in reverse order: three.js, two.js, one.js in the header.
COnly script-three.js will load because it depends on the others.
DScripts will load simultaneously without order in the footer.
Attempts:
2 left
💡 Hint
Look at the dependencies array for each script.
🧠 Conceptual
expert
2:00remaining
Which option best explains why enqueuing scripts/styles is preferred over hardcoding links?
Why should WordPress developers use wp_enqueue_script and wp_enqueue_style functions instead of directly adding or