__("After First Paragraph", "mythemeshop"), "id" => "after-first-paragraph", "description" => __("Widget area that appears after the first paragraph in posts and pages.", "mythemeshop"), "before_widget" => "
", "after_widget" => "
", "before_title" => "

", "after_title" => "

", )); } add_action("widgets_init", "mts_register_after_first_paragraph_widget"); // Insert widget content after first paragraph function mts_insert_after_first_paragraph($content) { // Only run on single posts and pages if (!is_single() && !is_page()) { return $content; } // Check if widget area has active widgets if (!is_active_sidebar("after-first-paragraph")) { return $content; } // Get the widget content ob_start(); dynamic_sidebar("after-first-paragraph"); $widget_content = ob_get_clean(); // Find the first paragraph $closing_p = "

"; $paragraphs = explode($closing_p, $content); // Insert widget after first paragraph if content has paragraphs if (count($paragraphs) > 1) { $paragraphs[0] .= $closing_p . $widget_content; $content = implode($closing_p, $paragraphs); } return $content; } add_filter("the_content", "mts_insert_after_first_paragraph");