Site logo

Archived topic

How to add adsense ads inside posts or articles

1 reply · Started by JAGDEEEP on October 2, 2015

Viewing posts 1–2 of 2

Hello Tom ,
i love your generate press theme its easy and responsive, i want to know two things about it
1. How to add adsense ads inside posts ? ( adsense ads are working well on my website)
by adding a shortcode inside it please give proper details where to add the adsense code in theme also
2. if i want to add a banner on homepage only , how it is possible ?

Hi there,

1. You could use a plugin like this: https://wordpress.org/plugins/ad-inserter/

Alternatively, you can place your Adsense code inside a shortcode and then use the shortcode.

function generate_adsense_shortcode() {
?>
    Place your adsense code in here
<?php }
add_shortcode( 'adsense', 'generate_adsense_shortcode' );

Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

Then you would use the [adsense] shortcode in your content.

2. Where would you want the banner to appear? You could use our GP Hooks add-on, and then use this if conditional:

<?php if ( is_front_page() ) : ?>
    Everything in here will only show up on the homepage
<?php endif; ?>

Then check the "Execute PHP" checkbox and you should be good to go :)

This archived topic is closed to new replies.