'; $paragraphs = explode( $closing_p, $content ); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $ad_code; } } $content = implode( '', $paragraphs ); } if($adposition == '50_of_the_content'){ $closing_p = '

'; $paragraphs = explode( $closing_p, $content ); $total_paragraphs = count($paragraphs); $paragraph_id = round($total_paragraphs /2); foreach ($paragraphs as $index => $paragraph) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( $paragraph_id == $index + 1 ) { $paragraphs[$index] .= $ad_code; } } $content = implode( '', $paragraphs ); } break; default: break; } //Displays all ads according to their settings paragraphs ends here } } } return $content; } /* * Create Shortcode adsforwp * Use the shortcode: [adsforwp id=""] */ add_shortcode( 'adsforwp', 'adsforwp_manual_ads' ); function adsforwp_manual_ads($atts) { $post_ad_id = $atts['id']; $current_post_data = get_post_meta(get_the_ID(),$key='',true); $visibility =''; if(array_key_exists('ads-for-wp-visibility', $current_post_data)){ $visibility = $current_post_data['ads-for-wp-visibility'][0]; } if($visibility != 'hide') { $ad_code = adsforwp_get_ad_code($post_ad_id); return $ad_code; } } /* * Generating html for ads to be displayed by post id */ function adsforwp_get_ad_code($post_ad_id){ $is_amp = 'no'; if ((function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint()) || function_exists( 'is_amp_endpoint' ) && is_amp_endpoint()) { $is_amp = 'yes'; } $custom_ad_code=""; $where_to_display=""; $ad_type=""; $amp_compatibility =''; $ad_code =''; $post_meta_dataset = get_post_meta($post_ad_id,$key='',true); if(array_key_exists('custom_code', $post_meta_dataset)){ $custom_ad_code = $post_meta_dataset['custom_code'][0]; } if(array_key_exists('wheretodisplay', $post_meta_dataset)){ $where_to_display = $post_meta_dataset['wheretodisplay'][0]; } if(array_key_exists('select_adtype', $post_meta_dataset)){ $ad_type = $post_meta_dataset['select_adtype'][0]; } if($ad_type !=""){ if(array_key_exists('ads-for-wp_amp_compatibilty', $post_meta_dataset)){ $amp_compatibility = $post_meta_dataset['ads-for-wp_amp_compatibilty'][0]; } switch ($ad_type) { case 'custom': if($is_amp== 'yes'){ if($amp_compatibility == 'enable'){ $ad_code = '
'.$custom_ad_code.'
'; } } if($is_amp== 'no'){ $ad_code = '
'.$custom_ad_code.'
'; } break; //adsense ads logic code starts here case 'adsense': $ad_client = $post_meta_dataset['data_client_id'][0]; $ad_slot = $post_meta_dataset['data_ad_slot'][0]; $width='200'; $height='200'; $banner_size = $post_meta_dataset['banner_size'][0]; if($banner_size !=''){ $explode_size = explode('x', $banner_size); $width = $explode_size[0]; $height = $explode_size[1]; } if($is_amp == 'yes'){ if($amp_compatibility == 'enable'){ $ad_code = '
'; } } if($is_amp == 'no'){ $ad_code = '
'; } break; case 'media_net': $ad_data_cid = $post_meta_dataset['data_cid'][0]; $ad_data_crid = $post_meta_dataset['data_crid'][0]; $width='200'; $height='200'; $banner_size = $post_meta_dataset['banner_size'][0]; if($banner_size !=''){ $explode_size = explode('x', $banner_size); $width = $explode_size[0]; $height = $explode_size[1]; } if($is_amp == 'yes'){ if($amp_compatibility == 'enable'){ $ad_code = '
;
'; } } if($is_amp == 'no'){ $ad_code = '
'; } break; default: break; } return $ad_code; } }