Skip to content

Instantly share code, notes, and snippets.

@dannyb195
Created May 28, 2015 23:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyb195/2c74017c52ef7d625c35 to your computer and use it in GitHub Desktop.
Save dannyb195/2c74017c52ef7d625c35 to your computer and use it in GitHub Desktop.
Inserting content after WP in-content paragraph (not really tested)
$content = get_post( 1558 );
$content = $content->post_content;
$content_array = explode( "\n", $content );
echo 'before<pre>';
print_r($content_array);
echo '</pre>';
foreach ( $content_array as $k => $v ) {
echo $k . ' ' . strlen( $v ) . ' </br></br>';
if ( 1 == strlen( $v ) || '<!--more-->' == $v ) {
unset( $content_array[ $k ] );
}
}
$content_array = array_values( $content_array );
array_splice( $content_array, 3, 0, '<div>sdf</div>' );
echo 'after<pre>';
print_r($content_array);
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment