WordPress.org

Ready to get started?Download WordPress

Forums

Shift content from left to center so to add adsense instead (18 posts)

  1. gurusurfer
    Member
    Posted 1 year ago #

    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

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    what theme are you using?

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

  3. gurusurfer
    Member
    Posted 1 year ago #

    Thanks,

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

  4. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    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.

  5. gurusurfer
    Member
    Posted 1 year ago #

    Yes i do have a child theme set up!

  6. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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; }

  7. gurusurfer
    Member
    Posted 1 year ago #

    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?

  8. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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

  9. gurusurfer
    Member
    Posted 1 year ago #

    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

  10. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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.

  11. gurusurfer
    Member
    Posted 1 year ago #

  12. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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.

  13. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

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

    .hentry h2 { clear: none; }

  14. gurusurfer
    Member
    Posted 1 year ago #

    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

  15. gurusurfer
    Member
    Posted 1 year ago #

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

    Thanks

  16. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    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 ) ) {
  17. gurusurfer
    Member
    Posted 1 year ago #

    Thanks a million, really appreciate the help..you are a great guy

  18. gurusurfer
    Member
    Posted 1 year ago #

    Please help!!

    I want to keep one post in the front page. i have achieved this already by assigning one post in the reading, but when i publish a newer post, that post is also appearing in the front page. i have tried to use as the instructions in the codex and inserted this code:

    $sticky = get_option( 'sticky_posts' );
    query_posts( 'p=' . $sticky[0] );

    in the functions.php, it works but then in my backend, i only get in the posts and pages section that post to appear.

    can someone please advice? thanks

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags