Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在WordPress帖子中指定自定义规范URL_Php_Wordpress_Seo_Canonical Link_Rel - Fatal编程技术网

Php 在WordPress帖子中指定自定义规范URL

Php 在WordPress帖子中指定自定义规范URL,php,wordpress,seo,canonical-link,rel,Php,Wordpress,Seo,Canonical Link,Rel,我们运营着1000多个网站,其中大部分都是为特定的体育赛事制作的。目前,我们有我们的作者专门为独特的内容写信给他们 然而,我们有两个主要网站,涵盖其垂直领域的所有事件;我们想从这些主要网站开始将内容联合到迷你网站 为了在谷歌眼中保持最佳实践,我们必须通过rel=canonical标记指定文章的原始来源——但是我们当前的插件AIOSEO(All-in-One SEO)不支持在帖子或页面上指定规范标记 有没有办法创建这样一个函数?请使用以下代码: function rel_canonical() {

我们运营着1000多个网站,其中大部分都是为特定的体育赛事制作的。目前,我们有我们的作者专门为独特的内容写信给他们

然而,我们有两个主要网站,涵盖其垂直领域的所有事件;我们想从这些主要网站开始将内容联合到迷你网站

为了在谷歌眼中保持最佳实践,我们必须通过rel=canonical标记指定文章的原始来源——但是我们当前的插件AIOSEO(All-in-One SEO)不支持在帖子或页面上指定规范标记


有没有办法创建这样一个函数?

请使用以下代码:

function rel_canonical() {
    if ( !is_singular() )
        return;

    global $wp_the_query;
    if ( !$id = $wp_the_query->get_queried_object_id() )
        return;

    $link = get_permalink( $id );
    echo "<link rel='canonical' href='$link' />\n";
}

// A copy of rel_canonical but to allow an override on a custom tag
function rel_canonical_with_custom_tag_override()
{
    if( !is_singular() )
        return;

    global $wp_the_query;
    if( !$id = $wp_the_query->get_queried_object_id() )
        return;

    // check whether the current post has content in the "canonical_url" custom field
    $canonical_url = get_post_meta( $id, 'canonical_url', true );
    if( '' != $canonical_url )
    {
        // trailing slash functions copied from http://core.trac.wordpress.org/attachment/ticket/18660/canonical.6.patch
        $link = user_trailingslashit( trailingslashit( $canonical_url ) );
    }
    else
    {
        $link = get_permalink( $id );
    }
    echo "<link rel='canonical' href='" . esc_url( $link ) . "' />\n";
}

// remove the default WordPress canonical URL function
if( function_exists( 'rel_canonical' ) )
{
    remove_action( 'wp_head', 'rel_canonical' );
}
// replace the default WordPress canonical URL function with your own
add_action( 'wp_head', 'rel_canonical_with_custom_tag_override' );
函数rel_canonical(){ 如果(!是单数()) 返回; 全局$wp___查询; if(!$id=$wp\u\u查询->获取被查询对象\u id()) 返回; $link=get_permalink($id); 回音“\n”; } //rel_canonical的副本,但允许对自定义标记进行重写 函数rel_canonical_与_custom_标记_override() { 如果(!是单数()) 返回; 全局$wp___查询; if(!$id=$wp\u\u查询->获取被查询对象\u id()) 返回; //检查当前帖子是否在“canonical_url”自定义字段中包含内容 $canonical\u url=get\u post\u meta($id,'canonical\u url',true); 如果(“”!=$canonical\u url) { //从中复制的尾部斜杠函数http://core.trac.wordpress.org/attachment/ticket/18660/canonical.6.patch $link=user_trailingslashit(trailingslashit($canonical_url)); } 其他的 { $link=get_permalink($id); } 回音“\n”; } //删除默认的WordPress规范URL函数 if(函数_存在('rel_canonical')) { 删除动作('wp_head','rel_canonical'); } //用您自己的函数替换默认的WordPress规范URL函数 添加动作('wp_head','rel_canonical_,带有自定义标记_override');
我们还可以为元关键字、元描述和元标题添加此选项

// function to insert All-in-One SEO Pack keywords
function keyword_insert() {
   global $post; // VERY important!

   // Retrieve keyword meta data from the SEO Pack
   $seokeywords = stripslashes(get_post_meta($post->ID, '_aioseop_keywords', true));

   // Default keywords in case none are specified for the page
   if (empty($seokeywords)) $seokeywords = "Homestar Runner, Strong Bad, The Cheat";

   // Output the html code
   $seokeyword_block = "<meta name=\"keywords\" content=\"".$seokeywords."\"/>\n";
   echo $seokeyword_block;
}

// function to insert All-in-One SEO Pack description
function description_insert() {
   global $post; // VERY important!

   // Retrieve description meta data from the SEO Pack
   $seodesc = stripslashes(get_post_meta($post->ID, '_aioseop_description', true));

   // Default description in case none is specified for the page
   if (empty($seodesc)) $seodesc = "Oh! I am Homestar, and This is A Website!";

   // Output the html code
   $seodesc_block = "<meta name=\"description\" content=\"".$seodesc."\"/>\n";
   echo $seodesc_block;
}

function title_insert() {
   global $post; // VERY important!

   // Retrieve title meta data from the SEO Pack
   $seotitle = stripslashes(get_post_meta($post->ID, '_aioseop_title', true));

   // Default description in case none is specified for the page
   if (empty($seotitle)) $seotitle = "";

   // Output the html code
   $seotitle_block = "<title>".$seotitle."</title><meta name=\"title\" content=\"".$seotitle."\"/>\n";
   echo $seotitle_block;
}
//插入多合一SEO包关键字的函数
函数关键字_insert(){
全局$post;//非常重要!
//从SEO包中检索关键字元数据
$seokeywords=stripslashes(get_post_meta($post->ID,'u aioseop_keywords',true));
//如果未为页面指定任何关键字,则为默认关键字
if(empty($seokeywords))$seokeywords=“Homestar Runner,Strong Bad,The Cheat”;
//输出html代码
$seokeyword\U block=“\n”;
echo$seokeyword_区块;
}
//函数插入一个SEO包中的所有描述
函数说明_insert(){
全局$post;//非常重要!
//从SEO包中检索描述元数据
$seodesc=stripslashes(get_post_meta($post->ID,'u aioseop_description',true));
//如果未为页面指定任何说明,则为默认说明
if(empty($seodesc))$seodesc=“哦!我是Homestar,这是一个网站!”;
//输出html代码
$seodesc_block=“\n”;
echo$seodesc_区块;
}
函数标题_insert(){
全局$post;//非常重要!
//从SEO包中检索标题元数据
$seotitle=stripslashes(获取帖子meta($post->ID,'aioseop_title',true));
//如果未为页面指定任何说明,则为默认说明
如果(空($seotitle))$seotitle=“”;
//输出html代码
$seotitle_block=“”.$seotitle.\n”;
echo$seotitle_区块;
}

您能用一下这个吗谢谢!这似乎就是我要找的。这至少应该归功于政府。此外,您复制的第一个函数(
rel_canonical
)是WordPress自身内部函数的一个示例,而不是您应该包含在自定义函数中的函数。此代码需要解释和来源。