This is a wild guess, because you didn’t provide (parts of) your template.
Anyway, most probably (if lessons.php
is a full template) there is get_header();
somewhere at the beginning of your template file.
If you put the very code you posted in your question before this it will render, as the wp_head
action is still to come.
// EDIT
My suggestion, however, is to put the function in your functions.php
. Then you’d have to adapt it to your needs, of course. But this approach is much more powerful (if you need this, that is). You could do things like this:
function wpdev_156346_wp_head() {
if ( is_user_logged_in() ) {
// Some logged-in-user stuff
}
if ( is_search() ) {
// Some search-only stuff
} elseif ( is_singular() ) {
switch ( get_post_type() ) {
case 'page':
// Some page-only stuff...
break;
case 'video':
// Some video-only stuff...
break;
}
}
}
add_action( 'wp_head', 'wpdev_156346_wp_head' );