0
是從一個函數返回AdSense代碼調用從作者發佈者ID元即the_author_meta('pub-id', $author_id
我如何在WordPress
CODE
//RECTANGLE Adsense UNit
function get_rectangle() {
global $post; $author_id=$post->post_author;
$rec_Ad.= '<div>';
$rec_Ad.= '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 300x250 -->
<ins class="adsbygoogle"
style="display:inline-block;width:300px;height:250px"';
if (get_the_author_meta('rectangle', $author_id)) {
$rec_Ad.= 'data-ad-client="ca-pub-'.the_author_meta('pub-id', $author_id).'"';
$rec_Ad.= 'data-ad-slot="'.the_author_meta('rectangle', $author_id).'"></ins>';
}
$rec_Ad.= '<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div>';
}
上面的代碼返回發佈者ID,但不整個adsense代碼
謝謝
我想,和它返回的HTML代碼 '91684956458900569117871855
' 你在一開始看到的數字是'酒館id'和'slot'一起 –剛編輯我的答案。我認爲問題在於'the_author_meta'被'get_the_author_meta'使用了insead,因爲它直接回應了這個值。見: https://developer.wordpress.org/reference/functions/the_author_meta/ – Quack
非常感謝。編輯實際上完成了這項工作 –