I have customised a theme by adding a second widget area/sidebar. I want this sidebar to always appear after the second paragraph on a single post page.
To do this, I have used the built in WP filter hook for the_content and made a filter function like:
function insert_secondary_widget_area($content) {
$paragraphs = explode('</p>',$content);
if (count($paragraphs) > 3) {
array_splice($paragraphs, 2, 0, '<!--#include virtual="sidebar-secondary.php" -->');
$content = implode($paragraphs);
}
return $content;
}
add_filter( 'the_content', 'insert_secondary_widget_area' );
However, when I test this, the included file never shows up in the content. I tested by replacing the include code with '<p>test</p>' and it showed up fine. I also tried using a PHP function include and require, but these did not work either. Bear in mind, this is my first time ever coding in PHP so I'm not sure if I'm doing this right.
What am I doing wrong?