Adsense To increase your clickthrough rate (CTR), you should place your ad on a more appropriate location and make it visible to the user. There are a number of ways to do that, including color adjustment, numbering, and placement, but the most effective way to do this is to insert AdSense into the body of the story (naturally, read through the text).
As a result, many operators are putting AdSense into the text, and they often find themselves putting ad code every time they write. Of course, this method has the advantage of being able to plant an optimized advertisement in the most optimized position for each article, but it is impossible to change, add or delete the advertisement size or type in future, You have to do your work manually. If you have experienced this kind of situation directly like Gimmeon, you can see how lethal it is.
To make sure this does not happen, and for more active and efficient settings, let's take a look at how you can use code to automatically insert AdSense behind a paragraph in the body of your text.
Code that identifies paragraphs and puts Adsense in the middle
First, let's start with the completed code
add_filter( 'the_content', 'prefix_insert_post_ads' ); function prefix_insert_post_ads( $content ) { $ad_code1 = 'Adsense Code'; $ad_code2 = 'Adsense Code'; if ( is_single() && ! is_admin() ) { $content = prefix_insert_after_paragraph( $ad_code1, 10, $content ); $content = prefix_insert_after_paragraph( $ad_code2, 20, $content ); return $content; } return $content; } 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; } } return implode( '', $paragraphs ); }
Code Description and Usage
The code shows what it is and how to use it.
This code is optimized for inserting ads like AdSense, but of course, it's an attractive one that can be used in other ways, not just by putting ads. This code is currently
In the Tistory, you can also put ads under the image through JavaScript. I think you can do it by paragraph because you can put filters by separating images. I will discuss this part later if I have a chance.