I have problem to add custom metadata to <head></head>
custom page template.
I googled a lot and found to add this to my custom page template
get_header();
some code here ......
load mysql data and put that data in function mySEO()
function mySEO() {
echo '
<title>titleeee</title>
<meta name="description" content="Page description. No longer than 155 characters." />
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<meta itemprop="image" content="http://www.example.com/image.jpg">
<meta name="twitter:site" content="@publisher_handle">
<meta name="twitter:title" content="Page Title">
<meta name="twitter:description" content="Page description less than 200 characters">
<meta name="twitter:creator" content="@author_handle">
<meta name="twitter:image" content="http://www.example.com/image.html">
<meta property="og:title" content="Title Here" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://www.example.com/" />
<meta property="og:image" content="http://example.com/image.jpg" />
<meta property="og:description" content="Description Here" />
<meta property="og:site_name" content="Site Name, i.e. Moz" />';
}
add_action('wp_head','mySEO');
///some code here...
get_footer();
BUT nothing happens i don't put anything in head of page... what is problem?
"VEL" responde to my question:
did you place add_action('wp_head','mySEO'); and mySEO function in functions.php? – vel
and call mySEO the function in your template
complete answer:
this is in function.php:
function mySEO($title,$description,$image,$url) { echo '
<title>'.$title.'</title>
<meta name="description" content="'.$description.'" />
<meta itemprop="name" content="'.$title.'">
<meta itemprop="description" content="'.$description.'">
<meta itemprop="image" content="'.$image.'">
<meta name="twitter:site" content="@Tw">
<meta name="twitter:title" content="'.$title.'">
<meta name="twitter:description" content="'.$description.'">
<meta name="twitter:creator" content="@Tw">
<meta name="twitter:image" content="'.$url.'">
<meta property="og:title" content="'.$title.'" />
<meta property="og:type" content="article" />
<meta property="og:url" content="'.$url.'" />
<meta property="og:image" content="'.$image.'" />
<meta property="og:description" content="'.$description.'" />
<meta property="og:site_name" content="SITE" />';
}
add_action("wp_head","mySEO");
in mypage.php (custom page template) just call function mySEO($title,$description,$image,$url);