php - How to add ad code in wordpress Single page without affecting the second single page template -


i using 2 different template single page. 1 sidebar , 1 without sidebar.

now want inject ad code in sidebar template.

could 1 give me code one.

note:

  1. the ad automatically inserted after every second paragraph. , have code.

    add_filter( 'the_content', 'prefix_insert_post_ads' );

    function prefix_insert_post_ads( $content ) {           if ( is_single() && ! is_admin()) {             return prefix_insert_after_paragraph( $ad_code, 2, $content );         }       return $content; }   function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {     $closing_p = '</p>';     $paragraphs = explode( $closing_p, $content );     foreach ($paragraphs $index => $paragraph) {          if ( trim( $paragraph ) ) {             $paragraphs[$index] .= $closing_p;         }          if ( $paragraph_id == $index + 1 ) {             $paragraphs[$index] .= $insertion;         }     }      return implode( '', $paragraphs ); } 

the above code display ad code both in sidebar template , no sidebar template. want display ad code in sidebar template. 1 please me how it.

you can check template used get_page_template_slug():

    if ( is_single() && ! is_admin() && get_page_template_slug() == 'template-sidebar.php') {         return prefix_insert_after_paragraph( $ad_code, 2, $content );     } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -