File Functions.php
contains such a code:
& lt;? php
Add_action ('WP_ENQueue_Scripts', 'add_theme_styles');
Function Add_Theme_Styles () {
Echo "Themes added";
}
File Header.php
has head
such contents:
& lt; head & gt;
& lt;? PHP WP_Head (); ? & gt;
& lt; / Head & gt;
As you can see a very simple code, but the text themes added is not displayed on the page, I can not understand what the problem is, tell me why does not work WP_HEAD ()
?
P.S. Also, after calling WP_Head ()
in the head
tag, the page appeared from above, approximately 30px, does this mean that WP_Head ()
is actually worked, but an error in the file functions.php
?
Answer 1, Authority 100%
This Hook for connecting styles and scrapits, and not output strings. You all withdraw in the HEAD of the document, and not in the body of the document.
add_action ('wp_enqueue_scripts', 'my_wp_head_css'); // Hook machine will work during WP_Head
Function My_WP_Head_css () {
wp_enqueue_style ('My_Head_style', get_stylesheet_directory_uri (). '/ css / my_style.css', array (), null);
}
as another option:
## CSS in head document
Add_action ('WP_Head', 'Hook_css');
Function Hook_css () {
Echo '& lt; style & gt; .wp_head_example {background-color: # F1F1F1; } & lt; / style & gt; ';
}
## JS in the head of the document
add_action ('WP_Head', 'hook_javascript');
Function hook_javascript () {
echo "& lt; script & gt; alert ('page is loading ...'); & lt; / script & gt;";
}