0
私はseo yoastでwoocommerceを使用しています。製品のSEOが完了していない場合、製品の詳細ページにカスタム分類のSEOの詳細を表示します。SEO Yoastのメタタグをカスタマイズする
function custom_metas()
{
if(is_product()){
global $post;
$prod_meta_title = get_post_meta($post->ID, '_yoast_wpseo_title', true);
$prod_meta_desc = get_post_meta($post->ID, '_yoast_wpseo_metadesc', true);
$prod_meta_kw = get_post_meta($post->ID, '_yoast_wpseo_focuskw', true);
if(empty($prod_meta_desc) && empty($prod_meta_title) && empty($prod_meta_kw))
{
$terms = get_the_terms($post->ID, 'brand');
$meta = get_option('wpseo_taxonomy_meta');
$terms = array_reverse($terms);
if(!empty($terms))
{
$set_meta = 0;
foreach($terms as $term)
{
if($set_meta == 1)
{
break;
}
$term_meta_title = $meta["brand"][$term->term_id]['wpseo_title'];
$term_meta_desc = $meta["brand"][$term->term_id]['wpseo_desc'];
$term_meta_keywords = $meta["brand"][$term->term_id]['wpseo_focuskw'];
if(!empty($term_meta_title) || !empty($term_meta_desc) || !empty($term_meta_keywords))
{
echo "coming";
//wpseo_replace_vars($term_meta_title, get_post($post_id, ARRAY_A))
apply_filters('wpseo_title', "tseting");
apply_filters('wpseo_metadesc', trim($term_meta_desc));
apply_filters('wpseo_metakey', trim($term_meta_keywords));
$set_meta = 1;
}
}
}
}
}
}
add_action("wp_head","custom_metas");
マイカスタム分類がブランドである:ここでは
は、私がしようとしていますものです。問題は、SEOの詳細が既存のものを上書きしていないことです。これをどのように達成できますか?
は、アクションの優先度でプレイしてみ? –
あなたのお返事ありがとうございます。NerijusMasikonis。あなたは、apply_filterの代わりにadd_actionを使用すると言っていますか? – Thomas
いいえ、add_actionをadd_action( "wp_head"、 "custom_metas"、99999)に変更してみてください。あなたはあなたの変更が最後に実行されることを確信していますか?それは役に立ちますか? –