I want to insert a shortcode to each custom post type by my function.php. I find this code.

function add_content_after_h2($content){
    if (is_single()) {
        $div = '<div>small bit of content</div>';
        $content = preg_replace('/(</h2>)/i', '1'.$div, $content);
    }

    return $content;
}

add_filter('the_content', 'add_content_after_h2');

It is working but the short code is inserted after h2 tag and to every post
. But i won’t get the shortcode after

and my post type name is listing. Please help me.

Read more here: How to add a short code after a Div.class?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: