Monday, October 31, 2022
HomeWordPress Developmentcapabilities - Totally different adverts on each web site on multisite setting

capabilities – Totally different adverts on each web site on multisite setting


I’m utilizing following code to insert advert in article, after eighth paragraph, by way of capabilities.php file:

add_filter( 'the_content', 'prefix_insert_post_ads' );
  
operate prefix_insert_post_ads( $content material ) {
      
    $ad_code="<div>Advertisements code goes right here</div>";
  
    if ( is_single() && ! is_admin() ) {
        return prefix_insert_after_paragraph( $ad_code, 8, $content material );
    }
      
    return $content material;
}
   
   
operate prefix_insert_after_paragraph( $insertion, $paragraph_id, $content material ) {
    $closing_p = '</p>';
    $paragraphs = explode( $closing_p, $content material );
    foreach ($paragraphs as $index => $paragraph) {
  
        if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
        }
  
        if ( $paragraph_id == $index + 1 ) {
            $paragraphs[$index] .= $insertion;
        }
    }
      
    return implode( '', $paragraphs );
}

Each webisite on community has totally different advert code, however in the identical time I’m utilizing similar theme on all websites, thus – just one capabilities.php file. I do know I can create a number of child-themes for each set up, however that’s not an choice right here.

Is there any means to make use of above code for multisite setting, however so as to add code to just one, common capabilities.php file?

Thanks…

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments