Closing Paragraph Tag Missing in Wordoress
The closing P tag
is stripped out of my blog posts whenever I use this code in my Functions.php file to insert an after a number of paragraphs. It leaves theunclosed. What could be wrong?
// Article Ads After X Paragraphs
/////////////////////////////////////
$mvp_post_inad = get_option('mvp_post_inad');
if (!empty($mvp_post_inad)) {
function mvp_post_ad_insert( $text ) {
if ( is_single() ) {
$mvp_post_inad = get_option('mvp_post_inad');
if ($mvp_post_inad) {
$ads_text = 'div class=mvp-post-ad-wrapspan class=mvp-ad-label' . esc_html__( 'Advertisement', 'zox-news' ) . '/spandiv class=mvp-post-ad'.do_shortcode(html_entity_decode($mvp_post_inad)).'/div/div';
}
$split_by = /p;
$mvp_post_freq = get_option('mvp_post_freq');
$insert_after = $mvp_post_freq; //number of paragraphs
// make array of paragraphs
$paragraphs = explode( $split_by, wptexturize($text));
if ( count( $paragraphs ) $insert_after ) {
$new_text = '';
$i = 1;
foreach( $paragraphs as $paragraph ) {
if( preg_match( '~(?:img|blockquote|ul|li)[ ]~', $paragraph )) {
$new_text .= $paragraph;
} else {
$new_text .= $paragraph . ( $i % $insert_after == 0 ? $ads_text : '' );
$i++;
}
}
return $new_text;
}
}
return $text;
}
add_filter('the_content', 'mvp_post_ad_insert');
}