Insert Post ads is a very simple and easy-to-use plug-in that can be installed online by searching for Insert post ads in the background plugin installation interface. You can insert multiple different ads in different paragraphs in the article and on the page, all you need to do is create a new ad in the background.
Then select the inserted paragraph position.
Plug-in method, there is nothing much to say, simple and easy to use.
Pure code to achieve WordPress in the article arbitrary paragraph position Insert Advertising Federation Code
Add the following code to the functions.php of the current topic:
The code is as follows |
Copy Code |
Add_filter (' The_content ', ' prefix_insert_post_ads '); Function Prefix_insert_post_ads ($content) { $ad _code = ' <div> Add your ad code </div> '; if (Is_single () &&! is_admin ()) { //modifies 2 of this paragraph return prefix_insert_after_paragraph ($ad _code, 2, $content); } r Eturn $content; } //Insert the functional code required by the advertisement function prefix_insert_after_paragraph ($insertion, $paragraph _id, $content) { $ closing_p = ' </p> '; $paragraphs = explode ($closing _p, $content); foreach ($paragraphs as $index => $paragraph) { if (Trim ($paragraph)) { $paragraphs [ $index]. = $closing _p; } if ($paragraph _id = = $index + 1) { $paragraphs [$index]. = $insertion; } & Nbsp;return implode (", $paragraphs); } |
The tribe here needs to add that we modify the ad code and the paragraph as described in the above comments.