Of course! Here is one way to do so:
add_action( 'wp_head', function () {
echo '<meta name="author" content="John Doe">';
} );
Hello Shea
many thanks this works fine.
Is it possible to have more control about the place in the header where, on which position, the tag is insert in?
I have to work much more with the snippets. Im not clear with the syntax.
Any suggestion where to learn this?
Tom
It shouldn’t really matter where in the <head> a meta tag is positioned. If need to have it earlier, you can specify the priority. By default it is 10; by making it lower the hook will be executed earlier.
Here is a simpler code example with an early priority:
add_action( 'wp_head', function () { ?>
<meta name="author" content="John Doe">';
?> }, 1 );
In this example, anything between the top line and the bottom line will be included in the <head> section. If you change the 1 on the bottom line, the content will appear lower in <head>.
These two example use action hooks and anonymous functions. Searching for “WordPress action hooks” or “PHP anonymous functions” will bring up a lot of resources on the matter.
The first one works well
The second one without the output
any ideas?
Whoops, there was a mistake in the second one. Here is a fixed version:
add_action( 'wp_head', function () { ?>
<meta name="author" content="John Doe">
<?php }, 1 );