How in WP can I add an area for the widget right inside the post text? For example, that the region was all the time after the second paragraph in the article.

Inserting a widget with a shortcode doesn’t fit; you need an area.

There is an idea to make a separate php file with the area code and connect it after the required paragraph, but I don’t imagine how to write it correctly

    1 answer 1

    For these purposes, there is a content filter hook. This code should be added to functions.php.

    function filter_my_content( $content ) { $addon = 'text to insert'; $pos = mb_strpos($content, '</p>'); $pos = ($pos + 4) + mb_strpos(mb_substr($content, $pos + 4), '</p>'); //конец 2-го абзаца $content = mb_substr($content, 0, $pos) . $addon . mb_substr($content, $pos + 4); return $content; } add_filter( 'the_content', 'filter_my_content' ); 
    • And where to register the area code for the widget itself? - Russian Bear
    • Replace the line $ addon = 'text to insert'; on what is needed. Those. in the $ addon variable write down the html code of the insert (widget) - KAGG Design
    • So the problem is that I do not have to insert the widget's html code, but the PHP area code for the widget is Russian Bear