正確的位置是functions.php。您添加過濾器,像這樣:
function add_post_content($content) {
$content .= $buttonCode
return $content;
}
add_filter('the_content', 'add_post_content');
希望這有助於 傑森
[更新]
對於這個我假設你所提供的代碼是按鈕的代碼如果沒有的話只需更換正確的按鈕代碼即可。
打開你的功能。PHP的theme文件夾中,並在底部添加此:
說得低於後添加:
function add_post_content($content) {
$buttonCode = "<div data-bg-color=\"#fdfdfa\" class=\"rdbWrapper\" data-show-read=\"1\" data-show-send-to-kindle=\"0\" data-show-print=\"0\" data-show-email=\"0"\ data-orientation=\"0\" data-version=\"1\"></div><script type=\"text/javascript\">(function() {var s = document.getElementsByTagName(\"script\")[0],rdb = document.createElement(\"script\"); rdb.type = \"text/javascript\"; rdb.async = true; rdb.src = document.location.protocol + \"//www.readability.com/embed.js\"; s.parentNode.insertBefore(rdb, s); })();</script>";
$content .= $buttonCode
return $content;
}
add_filter('the_content', 'add_post_content');
要放在它上面的帖子你加:
function add_post_content($content) {
$buttonCode = "<div data-bg-color=\"#fdfdfa\" class=\"rdbWrapper\" data-show-read=\"1\" data-show-send-to-kindle=\"0\" data-show-print=\"0\" data-show-email=\"0"\ data-orientation=\"0\" data-version=\"1\"></div><script type=\"text/javascript\">(function() {var s = document.getElementsByTagName(\"script\")[0],rdb = document.createElement(\"script\"); rdb.type = \"text/javascript\"; rdb.async = true; rdb.src = document.location.protocol + \"//www.readability.com/embed.js\"; s.parentNode.insertBefore(rdb, s); })();</script>";
$content = $buttonCode . $content;
return $content;
}
add_filter('the_content', 'add_post_content');
謝謝回答。我只希望在每一篇文章中。在帖子的頂部。所以我必須把代碼放入index.php? – racemike
這個或single.php,我以前忘了提及 - 取決於你的主題。如果single.php存在,可能你將不得不使用這個。只需備份並嘗試一下,就不會有太大的突破。 –