Support » Themes and Templates » Shift content from left to center so to add adsense instead

  • Hi

    I would really appericiate if someone can help me with this. I need to create a margin on the left side of my posts and in that margin i want to add my adsense to appear….skyscrapper 300*600

    Thanks

Viewing 15 replies - 1 through 15 (of 17 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    what theme are you using?

    is that for the index (and archive) pages?
    and/or for single posts and pages?

    Thanks,

    That would be for twenty twelve and for single posts and pages

    WPyogi

    (@wpyogi)

    Forum Moderator

    Do you have a child theme set up? That’s the first step if you are modifying theme files:

    http://codex.wordpress.org/Child_Themes

    A link to your site would be relevant as well.

    Yes i do have a child theme set up!

    Michael

    (@alchymyth)

    Forum Moderator

    one possibility – will add the adsense skyscraper into the top left corner of the post’s or page’s content:

    in functions.php of the child theme, add for example (enter your own adsense code):

    add_filter( 'the_content', 'adsense_column_in_content' );
    function adsense_column_in_content( $text ) {
    if( is_single() || is_page() ) {
    $adcode = '<script type="text/javascript"><!--
    google_ad_client = "pub-0123123123123";
    /* column */
    google_ad_slot = "8899999888";
    google_ad_width = 300;
    google_ad_height = 600;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>';
    $text = '<span class="adsense-column alignleft">' . $adcode . '</span>' . $text;
    }
    return $text;
    }

    add some css like this to fine adjust the alignement:

    .adsense-column.alignleft { margin-right: 10px; }

    Sorry for the dumb question, but when creating functions.php for the child theme, as i read in the codex that i must not copy all content from the parent theme..so what exactly do i have to copy?

    Michael

    (@alchymyth)

    Forum Moderator

    a brand-new functions.php in a child theme should start as:

    <?php
    
    ?>

    nothing before or after these lines;

    you don’t copy/paste anything;
    your new functions etc will get added inbetween.

    http://codex.wordpress.org/Child_Themes#Using_functions.php

    Got it, but the ad would push any h2 tag downwards, also the ad would not appear when the post is on frontpage static page

    Sorry for troubling

    Michael

    (@alchymyth)

    Forum Moderator

    in Twenty Twelve, the h tags are styled with ‘clear: both;’ – you might need to overwrite that with some custom styles.

    how did you get a post on the static front page?

    please post a live link to your site.

    Michael

    (@alchymyth)

    Forum Moderator

    also the ad would not appear when the post is on frontpage static page

    you don’t seem to have a static front page; all I see is the posts page at the front.

    for single posts and pages

    that is what you wanted, and that is the reason why the ads don’t show on the front page.

    having the ads in the posts page is slightly more complex, as one would need to check for the max allowed number of ads per web page, see TOS adsense.

    Michael

    (@alchymyth)

    Forum Moderator

    to pass the h2 in the post, you could add something like this to style.css of the child theme:

    .hentry h2 { clear: none; }

    Super thanks….worked for the h2…..What would you advice that i do so to keep this post in the frontpage, as i will be adding other posts, but i want to keep this one appearing in the frontpage….do i need to write is as a page and not a post?

    Thank you very much for your help

    And yes as per the TOS adsense rules, i am allowed 3 Ads per page.

    Thanks

    Michael

    (@alchymyth)

    Forum Moderator

    to keep this post in the frontpage,

    review http://codex.wordpress.org/Sticky_Posts

    to add the ad to the first post on the index page, change this line in the code:

    if( is_single() || is_page() ) {

    to:

    global $wp_query;
    if( is_single() || is_page() || ( is_home() && $wp_query->current_post == 0 ) ) {
Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Shift content from left to center so to add adsense instead’ is closed to new replies.