WordPress.org

Ready to get started?Download WordPress

Forums

Ads only in a few posts (6 posts)

  1. argie01
    Member
    Posted 4 years ago #

    Hello,

    I'm looking for a plugin to insert adsense ads just in a few posts.
    But all plugin I found inserts ads in ALL post, when the possibility to exclude some of them...

    So, do you know a plugin to do what I need? It could be as a normal ads, or as a wigted showed justs in a few posts.

    Thank you!

  2. MichaelH
    Member
    Posted 4 years ago #

  3. argie01
    Member
    Posted 4 years ago #

    Yes, I did it. But I'm looking for a plugin, for example for to use adsense.

  4. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    you could use shortcode;

    in functions.php, add something like, for instance to show adsense:

    function show_ads() {
        return '<div class="adsense">
    <!-- start of ad code -->
    
    <script type="text/javascript"><!--
    google_ad_client = "pub-1234567890";
    /* my_adsense */
    google_ad_slot = "123456789";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
    <!-- end of ad code -->
        </div>';
    }
    add_shortcode('adsense', 'show_ads');

    and in style.css, you could use .adsense { ..... } to format the adsense area.

    and in the few posts, enter [adsense] into the text of the post, on its own line, where you want to show the ad.

  5. argie01
    Member
    Posted 4 years ago #

    Thank you!! that code works fine!!
    But, is there a way to add "adsense" in my post as a comment, instead of use the brackets?

  6. melstan1
    Member
    Posted 4 years ago #

    ad the codes to your comments.php file instead of functions.php

Topic Closed

This topic has been closed to new replies.

About this Topic