Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Insert Content in WordPress after a certain amount of characters or words
add_filter('the_content', 'hjs_insert_content_after_chars_words');
function hjs_insert_content_after_chars_words($content) {
// only do this if post is longer than 1000 characters
$enable_length = 1500;
// insert after the first </p> after 500 characters
$after_character = 1500;
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 = 'Add Content Here';
array_splice($after_content, 1, 0, $text);
$after_content = implode('</p>', $after_content);
return $before_content . $after_content;
else {
return $content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.