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.
-
AuthorPosts
-
September 7, 2015 at 12:26 pm #524
Joseph
ParticipantHi 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.htmlRegards,
JosephSeptember 7, 2015 at 12:34 pm #525Chinmoy Paul
ModeratorAre 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 #1108Joseph
ParticipantHi Chinmoy,
Would you please guide me how to process this?July 16, 2016 at 11:43 am #1110Chinmoy Paul
ModeratorYou 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 #1112Joseph
ParticipantHi Chinmoy,
I just test the code, but it doesn’t float and shown as this: http://prntscr.com/btmjujJuly 16, 2016 at 2:28 pm #1113Chinmoy Paul
ModeratorYou 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 #1115Joseph
ParticipantHi 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 #1116Chinmoy Paul
ModeratorAre you did this?
$ad_code = '<div class="alignleft">Ads code goes here</div>';
Do not write new CSS
-
This reply was modified 4 years, 6 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.