Advertisement
arie_cristianD

add custom inline ads on AMP mode

Feb 17th, 2025
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. add_action( 'the_content', 'custom_inline_content_ads_1', 99 );
  2. add_action( 'the_content', 'custom_inline_content_ads_2', 99 );
  3.  
  4.  
  5. function custom_inline_content_ads_1( $content ) {
  6.     if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
  7.         $tag     = new \JNews\ContentTag( $content );
  8.         $pnumber = $tag->total( 'p' );
  9.         if ( $pnumber >= 6 ) {
  10.             $html = '
  11.            <div class="amp_ad_wrapper jnews_amp_inline_content_ads">
  12.                
  13.                 <h1>  CUSTOM ADS  1 </h1>
  14.            
  15.            </div>';
  16.  
  17.             $line    = $tag->find( 'p', 6 );
  18.             $content = jeg_string_insert( $tag->get_content(), $html, $line );
  19.         }
  20.     }
  21.  
  22.     return $content;
  23. }
  24.  
  25. function custom_inline_content_ads_2( $content ) {
  26.     if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
  27.         $tag     = new \JNews\ContentTag( $content );
  28.         $pnumber = $tag->total( 'p' );
  29.  
  30.         if ( $pnumber >= 9 ) {
  31.             $html = '
  32.            <div class="amp_ad_wrapper jnews_amp_inline_content_ads">
  33.                
  34.                 <h1>  CUSTOM ADS 2 </h1>
  35.            
  36.            </div>';
  37.  
  38.             $line    = $tag->find( 'p', 9 );
  39.             $content = jeg_string_insert( $tag->get_content(), $html, $line );
  40.         }
  41.     }
  42.  
  43.     return $content;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement