Skip to main content

Loading assets in a theme

LH WordPress template provides a way to load assets such as CSS, JavaScript, and Images files in a theme.

CSS

loadStyle function is used to load CSS files in a theme. This function must call before getHeader function.

<?php
// load style.css
loadStyle('style', 'data/css/style.css');

getHeader();

JavaScript

loadScript function is used to load JavaScript files in a theme. This function must call before getHeader function.

<?php
// load script.js after jQuery loaded
loadScript('script', 'data/js/script.js', array('jquery'));

getHeader();

Images

get_asset_url function or the_asset_url function are used to get the URL of the asset files in a theme.

<?php
// get the URL of the image file
$image_url = get_asset_url('data/images/image.jpg');
?>

<!-- display the URL of the image file -->
<img src="<?php the_asset_url('data/images/image.jpg'); ?>" alt="">