WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] html and google ads problem (3 posts)

  1. MyDaily-Gadget
    Member
    Posted 4 years ago #

    I know this is not quite the area of this forum, but maybe you guys have an idea.

    My problem looks like this ( the // lines before my excerpt):
    Link1

    I have that Google ads are causing this problem, because when i insert this code into the HTML section of my post:

    Link2

    I end up with this code, transformed:

    Link3.
    And those marked // are visible to the front page.Any idea guys?

  2. alchymyth
    Forum Moderator
    Posted 4 years ago #

    i am quite sure that you can't add javascript directly into the html editor of a post.

    to add google ads into a post or page, you could use shortcodes.

    http://codex.wordpress.org/Shortcode_API

    in functions.php of the theme, add:

    // [adsense]
    function add_adsense($atts) {
    
    return '<span class="adsense">
    <script type="text/javascript"><!--
    google_ad_client = "pub-0123412341234123";
    /* your google ads */
    google_ad_slot = "1234512345";
    google_ad_width = 468;
    google_ad_height = 60;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </span>';
    }
    
    add_shortcode('adsense', 'add_adsense');

    substitute your own google code.
    the span with the class .adsense is optional to style the ads (for instance use float:left; with some margins to let the text float around the ads);
    place them whereever you want in a post or page by typing [adsense] into the text.

    you might also be able to find a plugin to deal with adsense.

  3. MyDaily-Gadget
    Member
    Posted 4 years ago #

    thank you:) i edited the code above and it worked. Thanks a lot.

Topic Closed

This topic has been closed to new replies.

About this Topic