Add shortcode after x characters
-
I have this code to autoadd the shortcode in post after x character:
——————————————–
function inject_ad_text_after_n_chars($content) {
// only inject google ads if post is longer than 600 characters
$enable_length = 600;
// insert after the 590th character
$after_character = 590;
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);
$text = ‘<p>
<!– Google Ads Code –>
</p>
‘;
array_splice($after_content, 1, 0, $text);
$after_content = implode(”, $after_content);
return $before_content . $after_content;
}
else {
return $content;
}
}
//add filter to WordPress with priority 13
add_filter(‘the_content’, ‘inject_ad_text_after_n_chars’,13);}
—————————————
But i can’t figure how to replace “!– Google Ads Code –>” with [expander_maker more=”Read more” less=”Read less”] so i don’t get an error. Can you help me please
- The topic ‘Add shortcode after x characters’ is closed to new replies.