WordPress child theme is a powerful way to add header bidding advertising capability to a WordPress site. This blog discusses how to enable header bidding advertising in a WordPress site. More specifically, it describes how to integrate Prebid.js and Google Ad Manager with WordPress site.
To create a child theme, you create a folder first. In the folder, add a file named style.css and ensure the Template property has the same value as your primary theme name. For example, the style.css for theme Twenty Twenty-Four looks as follows.
/**
* Theme Name: AdRelevantis
* Template: twentytwentyfour
* ...other header fields
*/
If you want to put an ad in a template part, say header.html, you need to create a parts subfolder and add a header.html file there. In the header.html file, add code like
<!-- wp:group {"align":"wide","layout":{"type":"flex","justifyContent":"space-between","flexWrap":"wrap"}} -->
<div id="div-adrhorizontal" class="wp-block-group alignwide">
</div>
<!-- /wp:group -->
You need to also add a functions.php file in the child theme folder. In the functions.php file, you add an action as follows.
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script' );
where the function ‘themeslug_enqueue_script’ loads Prebid.js and Google Ad Manager libraries and creates ad units for your site. Please refer to the open source project wpchildthemesADR for details.
In the functions.php file, you add a filter as follows:
add_filter('the_content', 'add_incontent_adr');
where the function ‘add_incontent_adr’ adds ads in content. Please refer to the open source project wpchildthemesADR for details.
This gives you a starting point to display header bidding ads in your WordPress site. There are various ways to make changes to adapt to your situations. For example, you can use your own Google Ad Manager tags, create different ad units and change ad positions in a page, or even use different header bidding libraries.
Any questions or need more information? Contact us info@adrelevantis.com.