The preferred way is to use add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );
within your child theme functions.php
file or directly in your referral.php
template page. Either way, it’s by using add_action
and not by echoing into the <link>
tag.
Registering your style is also a recommended practice. The one benefit I would see in your case is that you could register all your styles in your functions.php
with for each file their dependencies, then you would have to enqueue only one handle in your referral page and WP would load all other files registered as dependencies of your referral-style.css
.
For instance, in functions.php
function themeslug_enqueue_style() {
wp_register_style( 'referral-style', get_stylesheet_directory_uri() . 'path/to/your/css-file', array( 'theme-stylesheet' ) );
wp_register_style( 'theme-stylesheet', get_stylesheet_uri() );
// load active theme stylesheet in all cases
wp_enqueue_style( 'theme-stylesheet' );
}
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );
and in referral.php
function my_referral_enqueue_style() {
wp_enqueue_style( 'referral-style' ); // will load theme-stylesheet automatically
}
add_action( 'wp_enqueue_scripts', 'my_referral_enqueue_style' );
of course you can omit this in referral.php
and still add a conditional in your functions.php
if( is_page( 'referral' ) ) {
wp_enqueue_style( 'referral-style' );
}
But I wanted to show you both ways