hello experts, My client running an affiliate site, he wants to show his AdSense ads only on the blog section and posts. I have tried to run the below-mentioned code in theme editor → single.php and that didn't work for me. if (is_category( 'blog' );) { //do nothing } else { //show google ads } Code (markup): Please can anyone help out here
Did you try?: if( '' !== get_post()->post_content ) { // do something } Code (markup): OR if ( !empty( get_the_content() ) ){ // do something } Code (markup): Reference: https://wordpress.stackexchange.com/questions/121359/if-the-post-has-content
Thank you guys, but I did differently. 1: Admin Panel -> Appearance ->Elements or you can click on GeneratePress -> Click on 2nd Tab (Elements) 2: Click on Add New -> Choose Element Type, I selected "Hook" 3: in the 2nd Section, I have inserted my Google ads code with the if-else condition. <?php if (in_category( 'blog' )) : ?> sidebar google ads code, it will show only in the blog section. site https://gotennisracquets.com <?php endif;?> Code (markup): 4: where my Hook show, I selected "after_right_sidebar_content" 5: Check Exclude PHP Display Rules 1: Location -> Posts -> All posts 2: All users This is all I did for showing my google ads in my blog section only in my GeneratePress theme.
Have you considered the official google wordpress plugin? It is by far the easiest way to get adSense running. Search the wordpress plugin directory for "Site Kit".
I have tried to run the below-mentioned code in theme editor → single.php and that didn't work for me. if (is_category( 'blog' );) { //do nothing } else { //show google ads } Code (markup): if (is_category( 'blog' )) { /*show google ads*/ } Code (markup): note semicolon removed from original code
I use Advanced Ads plugin. You can display by categories, specific pages, inside posts, etc Is very customizable