Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created February 19, 2016 00:36
Show Gist options
  • Save kurozumi/0150fcaaded3732781cb to your computer and use it in GitHub Desktop.
Save kurozumi/0150fcaaded3732781cb to your computer and use it in GitHub Desktop.
【WordPress】WordPress 用 AdSenseプラグインにプレースメントコードを続きを読むの直後に挿入する方法
<?php
add_filter('the_content', function($content){
$post_id = get_the_ID();
$adsense = "<ins id=\"more-{$post_id}\" style=\"display: none;\" class=\"adsbygoogle-placeholder\"></ins>";
return preg_replace('/(<span id="more-[0-9]+">)(<\/span>)/', "$1{$adsense}$2", $content);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment