在自定义页面模板 wordpress 中添加自定义元数据
add custom metadata in custom page template wordpress
我无法将自定义元数据添加到 <head></head>
自定义页面模板。
我在谷歌上搜索了很多,发现可以将其添加到我的自定义页面模板中
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();
但是没有任何反应,我没有在页面头部放置任何东西...有什么问题吗?
在调用 HEADER 之前,您应该在 PAGE 的顶部包含所需数据的值。
这样,这些值将可用于填充 HEADER 中包含的变量。
"VEL" 回复我的问题:
did you place add_action('wp_head','mySEO'); and mySEO function in functions.php? – vel
and call mySEO the function in your template
完整答案:
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");
在 mypage.php(自定义页面模板)中只需调用函数 SEO($title,$description,$image,$url);
我无法将自定义元数据添加到 <head></head>
自定义页面模板。
我在谷歌上搜索了很多,发现可以将其添加到我的自定义页面模板中
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();
但是没有任何反应,我没有在页面头部放置任何东西...有什么问题吗?
在调用 HEADER 之前,您应该在 PAGE 的顶部包含所需数据的值。
这样,这些值将可用于填充 HEADER 中包含的变量。
"VEL" 回复我的问题:
did you place add_action('wp_head','mySEO'); and mySEO function in functions.php? – vel
and call mySEO the function in your template
完整答案:
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");
在 mypage.php(自定义页面模板)中只需调用函数 SEO($title,$description,$image,$url);