Show code on posts but not pages

I have some code in my functions.php for putting ads on my site that looks like

add_action( ‘x_after_view_global__navbar’, ‘x_print_top_slider’ );
function x_print_top_slider(){
?>

<?php if(function_exists('the_ad_group')) the_ad_group(183); ?> <?php }

how can I make it so that it shows only on posts and not pages?

Hi,

To achieve that, please change your code to this.

add_action( 'x_after_view_global__navbar', 'x_print_top_slider' );
function x_print_top_slider(){
    if(function_exists('the_ad_group') && is_singular('post')) {
        the_ad_group(183);     
    }
}

For reference: https://codex.wordpress.org/Function_Reference/is_singular

Hope that helps

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.