How to add ads after a specific paragraph in Single Cloud Template?

Posted in: Newspaper
Post count: 27

Hey. Previously, I used the following code for entries:

// Вывод рекламных блоков после определенного абзаца записи
add_filter( ‘the_content’, ‘wpse_ad_content’ );
function wpse_ad_content( $content ) {
if( !is_single() )
return $content;
$paragraphAfter = 2; //Введите номер абзаца, после которого будет выводиться реклама.
$content = explode ( “</p>”, $content );
$new_content = ”;
for ( $i = 0; $i < count ( $content ); $i ++ ) {
if ( $i == $paragraphAfter ) {
$new_content .= ‘<ad code this>’;
}
$new_content .= $content[$i] . “</p>”;
}
return $new_content;
}

It’s not working right now. I am waiting for your help!

Post count: 35449

Hi,

For inline ads you can check this topic -> https://forum.tagdiv.com/topic/amp-and-mobile-theme/

Thank you!

Post count: 27

Thanks I will try this solution a little later!)

Post count: 27

Thank you! But this solution outputs the same block 2 times, and I need different ones. Help with the decision! Maybe my code for functions.php can be modified?

Post count: 35449

Hi,

What you can do is to set in tdb_state_single.php file inside the inline ads condition other conditions for each paragraphs to display a certain ad set in that file.

Thank you!

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.