Adding Javascript Code Manually After Number of Headings

[ad_1]

I want to add an ads unit before or after numbers of headings/part in all of my posts manually by insert Javascript code to the function php in theme child of my website

Any one can help me with this problem and tell me what code I should use.

[ad_2]
1 Comment
  1. You should probably use a plugin.

    Otherwise you need to filter the content and insert your script. Something like:

    `add_filter(‘the_content’, function ($content){`

    `if (!is_single()) return $content; //only do this for single posts`

    `$div = ‘<script>your script</script>’;`

    `return preg_replace(‘/</h3>/i’, “</h3>”.$div, $content, 1);`

    `});`

    This will place the code after the first H3 – change the final 1 in pregreplace to replace more occurences.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer