Wordpress: functions

rosiequ

Ruxin Qu

Posted on March 20, 2024

Wordpress: functions

To integrate links into WordPress, follow these steps:

Begin by creating a functions.php file within your WordPress theme directory. Within this file, define a function to enqueue external resources, ensuring that WordPress can load them as needed.

Within the function, when incorporating a CSS library, utilize wp_enqueue_style(). Within its parentheses, the first parameter serves as a descriptor, which can be any string. The second parameter is the URL link to the resource. Note that the link need not include 'https:' since, in some instances, HTTPS may not be available in local environments.

If you intend to include a JavaScript library, employ wp_enqueue_script(). This function accepts five parameters: the first is a descriptor, followed by the URL link to the script. Next is an array specifying any dependencies the script relies upon. Subsequently, indicate the version number, followed by a boolean value indicating whether the script should load after the page has fully loaded (set to true to ensure the JavaScript loads at the page's end).

After defining the function, within the PHP code's conclusion, call the function using add_action('wp_enqueue_scripts','functionName'). This ensures that the function is invoked when necessary.

💖 💪 🙅 🚩
rosiequ
Ruxin Qu

Posted on March 20, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related