Forums

[resolved] Add adsense code to the theme without plugin (19 posts)

  1. Kumuluzz
    Member
    Posted 7 months ago #

    How do you add adsensecode to the theme so it shows on every post?
    And how do you make it appear in the middle of the browser (not far to the left)

    I want to insert the code without a plugin so i can make a A/B test on adsense

  2. alchymyth
    The Sweeper
    Posted 7 months ago #

    for every post, add the code into the loop (in index.php, single.php, archive.php, etc; depending on your theme)

    http://codex.wordpress.org/The_Loop

    or create some shortcode, for example, and add this to the post(s) of your choice.

    And how do you make it appear in the middle of the browser (not far to the left)

    this depends on the layout of your theme, and on the location of your ads.

  3. Gabe Young
    Member
    Posted 7 months ago #

    You can simply drop the adsense code into the HTML body of your post if you want it between paragraphs.

  4. Kumuluzz
    Member
    Posted 7 months ago #

    My site is http://veisworld.com/
    Using the Twenty Eleven 1.2

    But i can try adding it into the loop then

    Do you know where to insert it for getting it in the sidebar? (i know you can add a text box widget, but i want the ad in the code, again for a/b)

  5. Kumuluzz
    Member
    Posted 7 months ago #

    @Gabe Young

    I know i can do that, but it's just more simpel to add it to the theme. Then i don't have to think about it everytime i add a post

  6. Kumuluzz
    Member
    Posted 7 months ago #

    First of all i just want it on a single post. This is my code for single.php:

    [34 lines of code moderated as per the Forum Rules. Please use the pastebin]

    Where should i then add the code from adsense; if i want it in the beginning and in the middle?
    And what should i write to allign it in the middle of the browser?

  7. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Do not edit the Twenty Eleven theme. It is the default WordPress 3.2 theme and having access to an unedited version of the theme is vital when dealing with a range of site issues.

    Create a child theme for your changes. Once your child theme is active, we should be able to help with the customisation.

  8. Kumuluzz
    Member
    Posted 7 months ago #

    Okay, thanks. Then i'll do that first :)

  9. Kumuluzz
    Member
    Posted 7 months ago #

    I still can figure out where to put the ad code.

    I have made my child theme, but still don't know about the code.

  10. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    First you need to clarify when you want the ad to be displayed. In the single post page or in-between posts in the main posts page? If it's the former, you'll need a copy of content-single.php in your theme. If it's the latter, you'll need a copy of content.php. If you're using post formats, you'll probably also need a copy of all of the other content-xxx.php files as well.

  11. Kumuluzz
    Member
    Posted 7 months ago #

    I wanted one in the sidebar, otherwise none at the homepage nor pages.
    And then 3 on posts, beginning, middle and end

    I'll just copy all of them then

  12. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    I wanted one in the sidebar

    What about just adding that one via a Text widget?

    And then 3 on posts, beginning, middle and end

    Where? Single posts? Main posts page?

  13. Kumuluzz
    Member
    Posted 7 months ago #

    I'm not sure what you mean about post formats, but i've copied content-single.php and content.php

  14. Kumuluzz
    Member
    Posted 7 months ago #

    I know i can do it via the Text widget, but then i can't make an a/b test

    Single posts, only there

  15. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    I know i can do it via the Text widget, but then i can't make an a/b test

    Sorry? I don't follow you...

    You're not going to able to place an ad in the middle of the post content but you could place ads at the top & bottom by adding the first ad block before <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> and the last after </article><!-- #post-<?php the_ID(); ?> --> in content-single.php.

  16. Kumuluzz
    Member
    Posted 7 months ago #

    The easiest way to place ads is with a plugin, which i've already used.
    But i wanna make a a/b tests for adsense, which i can't find any plugin for, so i have to do it my self in the code.
    And if i try to put a test in the text widget, then it just end up showing both ads and some part of the code

    But thanks about the content-single.php! :)

  17. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

  18. Kumuluzz
    Member
    Posted 7 months ago #

    I think something like that could work, but it's very complicated for me and i'm still not sure how the widget works. So for know i'll just stick to the content-single.php

  19. rukky
    Member
    Posted 7 months ago #

    widget logic helps you determine where certain widgets should appear. its very useful and eliminates the use of multiple side bars.

Reply

You must log in to post.

About this Topic