我想使用字数统计来拆分我的"the_content();“。第一部分显示400字和谷歌添加第二部分显示word的其余部分,并显示谷歌添加喜欢明智的。有什么想法吗?
发布于 2019-02-25 13:06:22
如果下面的代码对您有帮助,您仍然可以使用它
add_filter('the_content','filterContentForGoogleAds',10,1);
function filterContentForGoogleAds($content){
$contentToReturn = '';
$mycontent = '</br>Your google ads code here</br>';
$CompleteContent = $content;
$ContentArray = explode (' ',$CompleteContent);
$ContentCLength = count($ContentArray);
$firstHalfEnd = ceil($ContentCLength/2);
for ($i=0; $i < $firstHalfEnd; $i++) {
$contentToReturn .= ' '.$ContentArray[$i];
}
$contentToReturn .= $mycontent;
for ($i=$firstHalfEnd; $i < $ContentCLength; $i++) {
$contentToReturn .= ' '.$ContentArray[$i];
}
return $contentToReturn;
}
https://stackoverflow.com/questions/54865652
复制