• Home
  • Blog
  • Showcase
  • Setup Docs
    • Sunshine Help
    • Flex Help
  • Support
    • Support Area
    • Contact us
    • Feedback
  • Connect
    • Newsletter
    • Twitter
    • Facebook
  • My Account
  • Flex
  • Sunshine
Support : Simple Pro Themes

Support : Simple Pro Themes

[Support request] Floating left or right ads in single post

If you have purchased a product, please enter the email address that you used to register at time of purchase.
Log In
Lost Password

Create an Account
  • Your username must be unique, and cannot be changed later.
  • We use your email address to email you a secure password and verify your account.

Support › Forums › General Tips › Floating left or right ads in single post

  • This topic has 7 replies, 2 voices, and was last updated 4 years, 6 months ago by Chinmoy Paul.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • September 7, 2015 at 12:26 pm #524
    Joseph
    Participant

    Hi support,
    I would really appreciate if you could help how to place floating left or right ads in a single post? Example screenshot: http://prntscr.com/8dlcm8 or live site @ http://www.irrawaddy.org/asia/malaysias-anti-corruption-efforts-undermined-by-scandal-questions.html

    Regards,
    Joseph

    September 7, 2015 at 12:34 pm #525
    Chinmoy Paul
    Moderator

    Are you using custom filed for Ads block? Use “the_content()” filter you can float the Ads. You will add the custom php code in functions.php file.

    July 16, 2016 at 9:27 am #1108
    Joseph
    Participant

    Hi Chinmoy,
    Would you please guide me how to process this?

    July 16, 2016 at 11:43 am #1110
    Chinmoy Paul
    Moderator

    You can try this code

    //Insert ads after second paragraph of single post content.
    
    add_filter( 'the_content', 'prefix_insert_post_ads' );
    
    function prefix_insert_post_ads( $content ) {
    	
    	$ad_code = '<div>Ads code goes here</div>';
    
    	if ( is_single() && ! is_admin() ) {
    		return prefix_insert_after_paragraph( $ad_code, 2, $content );
    	}
    	
    	return $content;
    }
     
    // Parent Function that makes the magic happen
     
    function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
    	$closing_p = '</p>';
    	$paragraphs = explode( $closing_p, $content );
    	foreach ($paragraphs as $index => $paragraph) {
    
    		if ( trim( $paragraph ) ) {
    			$paragraphs[$index] .= $closing_p;
    		}
    
    		if ( $paragraph_id == $index + 1 ) {
    			$paragraphs[$index] .= $insertion;
    		}
    	}
    	
    	return implode( '', $paragraphs );
    }

    Source: wpbeginner.com

    July 16, 2016 at 1:26 pm #1112
    Joseph
    Participant

    Hi Chinmoy,
    I just test the code, but it doesn’t float and shown as this: http://prntscr.com/btmjuj

    July 16, 2016 at 2:28 pm #1113
    Chinmoy Paul
    Moderator

    You will add the CSS like float: left or float: right in your style.css file. Fund the correct class name of your ad markup and right the CSS.e.g
    Your ads class name is my-ads. Then you will write this

    .my-ads{
       float: left;
    }

    2nd option: You can assign predefined CSS class name alignleft or alignright In your ads HTML markup.

    • This reply was modified 4 years, 6 months ago by Chinmoy Paul.
    July 16, 2016 at 3:24 pm #1115
    Joseph
    Participant

    Hi Chinmoy,
    I try to name my ads as alignleft

    .alignleft{
    float: left;
    }

    but it doesn’t float.

    This plugin https://wordpress.org/plugins/ad-inserter/ has float setting, but I prefer not to use plugin if possible. Would you be able to get any code from this plugin 🙂

    Regards,

    July 16, 2016 at 3:43 pm #1116
    Chinmoy Paul
    Moderator

    Are you did this?

    $ad_code = '<div class="alignleft">Ads code goes here</div>';

    Do not write new CSS

  • Author
    Posts
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Log In

Copyright © 2021 · Simple PRO Themes for Genesis Framework · About · FAQs · Contact · Affiliates