Simplicityの特徴 › フォーラム › 要望・機能追加など › 好きなところにウィジェット登録したアドセンスを挿入できる機能
-
投稿者投稿
-
-
2017年9月5日 3:32 AM #55704
田中 颯太
ゲストウィジェットで登録したアドセンスコードを各記事別に自分の入れたい場所に挿入できる機能を希望します。
アドセンスコードを各記事のHTMLに直接貼り付けることも不可能ではありませんが、そうするとスマホとPCで別の広告を表示するという事が出来なくなってしまいます。
可能であれば、記事内にショートコードを挿入することでスマホにはスマホ用のアドセンスコード、PCにはPC用のアドセンスコード、が自動的に挿入できるような機能を追加していただきたいです。
もし、カスタマイズで解決する内容であれば、カスタマイズのカテゴリーで新たに質問を立てます。
お忙しいところ申し訳ありませんが、なにとぞお願いいたします。 -
2017年9月5日 8:00 PM #55713
わいひら
キーマスターfunctions.phpに以下を追記で実装出来るっぽい。
//[ad]ショートコードに対して広告を表示する if ( !function_exists( 'replace_ad_shortcode_to_advertisement' ) ): function replace_ad_shortcode_to_advertisement($the_content){ $ad_shortcode = '[ad]'; ob_start();//バッファリング get_template_part('ad');//広告貼り付け用に作成したテンプレート $ad_template = ob_get_clean(); $the_content = str_replace('<p>'.$ad_shortcode.'</p>', $ad_template, $the_content); $the_content = str_replace($ad_shortcode, $ad_template, $the_content); return $the_content; } endif; add_filter('the_content', 'replace_ad_shortcode_to_advertisement');
機能として追加するかは、検討中。
-
2017年9月5日 8:16 PM #55714
わいひら
キーマスターこっちの方がより良いかも。
//[ad]ショートコードに対して広告を表示する if ( !function_exists( 'replace_ad_shortcode_to_advertisement' ) ): function replace_ad_shortcode_to_advertisement($the_content){ $ad_shortcode = '[ad]'; ob_start();//バッファリング get_template_part('ad');//広告貼り付け用に作成したテンプレート $ad_template = ob_get_clean(); $the_content = preg_replace('{^(<p>)?'.preg_quote($ad_shortcode).'(</p>)?$}m', $ad_template, $the_content); return $the_content; } endif; add_filter('the_content', 'replace_ad_shortcode_to_advertisement');
-
2017年9月5日 8:21 PM #55715
-
2017年9月5日 11:21 PM #55716
田中 颯太
ゲストPCページ、スマホページでは正常に機能しましたが、AMPページでスポンサーリンクという文字列だけが表示される状態になってしまいました。
初めに質問した時にAMPを使用していないような書き方をしてしまいすみません。
AMPを含めると複雑になるかと思い、そのように書きましたが、AMP画面でスポンサーリンクという文字が表示されないようにするにはどのようにしたらいいでしょうか。
欲を言えば、AMP画面でも[ad]コードで表示できるようになると助かります。
自分でも少し弄って見たのですが、成功できませんでした。
お願いいたします。 -
2017年9月5日 11:37 PM #55717
田中 颯太
ゲストもう少し自分で試した結果、解決する事が出来ました。
有難うございす。
とても感謝しております。 -
2017年9月6日 12:45 AM #55719
田中 颯太
ゲストすみません。
できたと思ったのですが、どうしてスポンサーリンクの文字が二重になってしまいます。 -
2017年9月6日 5:29 AM #55721
田中 颯太
ゲストなんども厚かましく質問する形になって申し訳ありません。
色々試したところ、私の中での一番の理想はショートコードで挿入するための専用の機能が適しているという結論に至りました。
理想の広告体系としては、記事下ウィジェットでダブルレクタングルを全ての記事において固定して使用し、記事中の広告は各記事で異なった場所にショートコードで挿入できるようにすることです。ショートコードはamp、スマホ、pc全てにおいて適用されるのが理想です。
可能であればで構いませんのでお願いいたします。 -
2017年9月6日 5:52 PM #55728
わいひら
キーマスターAMPページも対応するには、こんな感じでいけるかと思います。
//[ad]ショートコードに対して広告を表示する if ( !function_exists( 'replace_ad_shortcode_to_advertisement' ) ): function replace_ad_shortcode_to_advertisement($the_content){ $ad_shortcode = '[ad]'; ob_start();//バッファリング if (is_amp()) { get_template_part('ad-amp');//AMP用広告コート } else { get_template_part('ad');//通常ページ用広告コード } $ad_template = ob_get_clean(); $the_content = preg_replace('{^(<p>)?'.preg_quote($ad_shortcode).'(</p>)?$}m', $ad_template, $the_content); return $the_content; } endif; add_filter('the_content', 'replace_ad_shortcode_to_advertisement');
-
2017年9月6日 5:55 PM #55729
わいひら
キーマスターAMPページは気をつけないと、アドセンスポリシー違反になる可能性も高そうなので、一応AMPページでは広告を表示しないバージョンのコードも掲載。
//[ad]ショートコードに対して広告を表示する if ( !function_exists( 'replace_ad_shortcode_to_advertisement' ) ): function replace_ad_shortcode_to_advertisement($the_content){ $ad_shortcode = '[ad]'; ob_start();//バッファリング if (is_amp()) { //get_template_part('ad-amp');//AMP用広告コート } else { get_template_part('ad');//通常ページ用広告コード } $ad_template = ob_get_clean(); $the_content = preg_replace('{^(<p>)?'.preg_quote($ad_shortcode).'(</p>)?$}m', $ad_template, $the_content); return $the_content; } endif; add_filter('the_content', 'replace_ad_shortcode_to_advertisement');
-
2017年9月6日 11:53 PM #55734
田中 颯太
ゲストこんばんは。
試してみたところ、コンテンツ部分が丸々消えてしまうという結果になりました。 -
2017年9月7日 12:19 AM #55739
わいひら
キーマスターコピペ時、不要なコードを削除したとき、必要なものも削除してしまったみたい。
修正しておきました。 -
2017年9月7日 1:51 AM #55740
田中 颯太
ゲストpc,スマホ,ampのすべてにおいて理想の形が出来上がりました。
テーマ自体が素晴らしい上に、これほどにまでサポートが充実していている無料テーマは他にないと思います。
とても感謝しております。
これからもよろしくお願いします。 -
2017年9月7日 8:29 PM #55747
わいひら
キーマスターうまくいったようでよかったです^^
-
-
投稿者投稿
- トピック「好きなところにウィジェット登録したアドセンスを挿入できる機能」には新しい返信をつけることはできません。