Skip to content

CHICPRO

  • Life Log
  • Cycling Log
  • Photo Log
    • Portrait
    • Landscape
    • Flower
    • Etc
  • Coding Log
  • Information

[WP] 포스트 상하단에 애드센스 광고 노출 플러그인

2017-11-14 by 편리

워드프레스 포스트 상하단에 구글 애드센스 광고를 출력하는 플러그인이다. 애드센스 광고 설정 기능은 제공하지 않는 단순한 기능의 플러그인으로 플러그인 적용 전 post-adsense.php 파일에서 자신의 애드센스 광고 설정을 해야 정상적으로 광고가 노출된다.

플러그인 : post-adsense.zip

<?php

/**
 * @package Post Adsense
 * @version 1.0
 */
/*
Plugin Name: Post Adsense
Plugin URI: https://chicpro.dev/
Description: This plugin prints Adsense Ads.
Author: Seongho Jang
Version: 1.0
Author URI: https://chicpro.dev/
*/

// Register js and style sheet.
add_action( 'wp_enqueue_scripts', 'register_post_adsense_style', 100 );
add_action( 'wp_enqueue_scripts', 'register_post_adsense_js', 100 );

/**
 * Register adsense Js
 */
function register_post_adsense_js() {
    wp_register_script('post-adsense-js', '//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js');
    wp_enqueue_script('post-adsense-js');
}

/**
 * Register style sheet.
 */
function register_post_adsense_style() {
    wp_register_style( 'post-adsense-style', plugins_url( 'post-adsense/style.css' ) );
    wp_enqueue_style( 'post-adsense-style' );
}

add_filter ('the_content', 'post_adsense_print', 100);

function post_adsense_print($content) {
    if(is_single()) {
        if(!$content)
            return $content;
        
        $top_ads = '<div id="adsense-post-top" class="adsense-post">
                        <ins class="adsbygoogle"
                            style="display:block"
                            data-ad-client="ca-pub-16166"
                            data-ad-slot="90868"
                            data-ad-format="auto"></ins>
                        <script>
                        (adsbygoogle = window.adsbygoogle || []).push({});
                        </script>
                    </div>';
        $btm_ads = '<div id="adsense-post-bottom" class="adsense-post">
                        <ins class="adsbygoogle"
                            style="display:block"
                            data-ad-client="ca-pub-16166"
                            data-ad-slot="27266"
                            data-ad-format="auto"></ins>
                    <script>
                    (adsbygoogle = window.adsbygoogle || []).push({});
                    </script>
                    </div>';
        
        $content = $top_ads . $content . $btm_ads;
    }

    return $content;
}
$top_ads와 $btm_ads 부분 에서 data-ad-client, data-ad-slot 값을 자신의 애드센스 설정으로 반드시 변경하셔야 합니다.

Post navigation

Previous Post:

Ubuntu 16.04에서 ngx_pagespeed 모듈을 포함한 nginx deb 패키지 컴파일

Next Post:

[WP] 워드프레스에 키보드 단축키 추가 플러그인

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • php 배열 연산에서 + 와 array_merge 의 차이
  • pcntl_fork 를 이용한 다중 프로세스 실행
  • 아이폰 단축어를 이용하여 주중 공휴일엔 알람 울리지 않게 하기
  • 구글 캘린더 전체일정 재동기화
  • OpenLiteSpeed 웹서버에 HTTP 인증 적용
  • OpenLiteSpeed 웹어드민 도메인 연결
  • WireGuard를 이용한 VPN 환경 구축
  • Ubuntu 22.04 서버에 OpenLiteSpeed 웹서버 세팅
  • 맥 vim 세팅
  • 우분투 시스템 터미널쉘 zsh 로 변경

Recent Comments

  • 편리 on 업무관리용 그누보드 게시판 스킨
  • 임종섭 on 업무관리용 그누보드 게시판 스킨
  • 캐논 5D 펌웨어 | Dslr 펌웨어 업그레이드 방법 82 개의 베스트 답변 on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • Top 5 캐논 5D 펌웨어 Top 89 Best Answers on 캐논 EOS 30D 펌웨어 Ver 1.0.6 , EOS 5D 펌웨어 Ver 1.1.1
  • 편리 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 임팀장 on 워드프레스 애니메이션 gif 파일을 mp4로 변환하여 출력하기
  • 편리 on Notepad++ NppFTP 플러그인 수동 설치
  • paul-j on Notepad++ NppFTP 플러그인 수동 설치
  • YS on Windows 10 iCloud 사진 저장 폴더 변경
  • 편리 on Docker를 이용한 Centos7 + httpd + php 5.4 개발환경 구축

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
© 2025 CHICPRO | Built using WordPress and SuperbThemes