Adding <head> Files in a WordPress Template

Problem: want to create a WP Template that uses a different CSS file from the Theme CSS so that the HTML structure remains the same but the Template layout will be different, dictated by the CSS. It works to put a <link> to the CSS in the Template HTML but then it gets rendered in <body> instead of the <head>, which is a little wonky. How to get the CSS into the <head>?

Solution: Insert this PHP code into the beginning of your Template file before the get_header() call…

<?php
function mytemplate_head () {

echo ‘<link rel=”stylesheet” type=”text/css” href=”‘ . get_bloginfo(‘template_directory’) . ‘/mytemplate.css” />’;

}
add_action ( ‘wp_head’, ‘mytemplate_head’ );
?>

Links

get_bloginfo
add_action
get_header