I have google adsense script which I can place it in different positions on my page.
I also have body text where the description of each post
is and I want to know how can I add adsense script dynamically into my posts body text? (Google suggested to place it after second paragraph).
I am using laravel
and this is how I get my body part of each post
{!! $post->body !!}
Sample of Google adsense code:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-6565454545454774"
data-ad-slot="548855465655"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Any idea?
Update
single post function
//single post
public function single($slug)
{
$post = Post::where('slug', $slug)->where('publish', '=', 'y')->firstOrFail();
$post->addPageView();
$previous = Post::where('slug', '<', $post->slug)->max('slug');
$next = Post::where('slug', '>', $post->slug)->min('slug');
$products = Product::all()->where('status', 'enable')->random(3);
$categories = PostCategory::all();
$settings = Setting::all();
$author = AuthorInfo::where('user_id', $post->user->id)->first();
return view('front.singlepost', compact('post', 'previous', 'next', 'products','categories', 'settings','author'));
}
[and using the `substr_replace` function.](https://stackoverflow.com/a/17880260/3585500)
– ourmandave Oct 23 '18 at 11:40....
` and whatever else we put while creating that content in ckeditor. – mafortis Oct 23 '18 at 11:49` tag?
– thisiskelvin Oct 23 '18 at 13:05