Skip to content

Snippet: Insert Advertisement (Adsense) or Banner Above Blog Posts

Using theme hooks you can easily add any code above your post content. This includes an advertisement banner or Adsense. Here is a sample snippet of code showing how you can add a banner at the top of all blog posts. If you want a standard image banner simply replace the link href attribute with your advertisement link and the img src attribute with your image URL. If you wanted to display Adsense, BuysellAds or another custom code simply delete the whole link HTML and dump your custom code in there.

add_action( 'wpex_hook_primary_before', function() {

	// Bail if not a singular post
	if ( ! is_singular( 'post' ) ) {
	} ?>

	<div class="container textcenter" style="margin-bottom:30px">

		<a href=""><img src=""></a>


<?php } );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top