Hi all,
I have made some modifications to my Wordpress installation which change the behaviour of “the_content” but I only want these changes to have an effect on single posts, not pages.
How can I make it so that it only changes “the_content” if it is a single post and not a page?
This is the code from my functions.php
function inject_ad_text_after_n_chars($content) {
// only do this if post is longer than 1000 characters
$enable_length = 3000;
// insert after the first </p> after 500 characters
$after_character = 1500;
ob_start();
related_posts();
$text = ob_get_clean();
if (is_single() && strlen($content) > $enable_length) {
$before_content = substr($content, 0, $after_character);
$after_content = substr($content, $after_character);
$after_content = explode('</p>', $after_content);
array_splice($after_content, 1, 0, $text);
$after_content = implode('</p>', $after_content);
return $before_content . $after_content;
}
else {
return $content . $text;
}
}
add_filter('the_content', 'inject_ad_text_after_n_chars');
I only want this to happen on single posts, not pages. But my pages also use “the_content” so it’s coming up on them too.