It is common to show a piece of content, or specific page element in the middle of each blog post on your WordPress website. The piece of content can be table of content, ads, or related articles.
Add these code in your plugin:
add_filter( 'the_content', 'myplugin_inject_content' ); function myplugin_inject_content( $content ) { $additional_content = '<div>My ads or content</div>'; if ( is_single() ) { $paragraph_position = 0; //position start from 0 $content = myplugin_prefix_insert_after_paragraph( $additional_content, $paragraph_position, $content ); } return $content; } function myplugin_prefix_insert_after_paragraph( $additional_content, $paragraph_position, $content ) { $paragraphs = explode( '</p>', $content ); foreach ($paragraphs as $key => $paragraph) { //add closing p back if ( trim( $paragraph ) != '' ) { $paragraphs[$key] .= '</p>'; } //add additional content at the wanted position if ( $paragraph_position == $key ) { $paragraphs[$key] .= $additional_content; } } return implode( '', $paragraphs ); }
If you don’t want to code, you can install any Ads manager plugins. Most of them allow where the content can be showed on a blog post.