Join the Soledad Facebook Users Group here
for Share, assistance, discussion, and Updates related to Soledad WordPress Theme.

If you can't create a new ticket - you can send us an email via our contact form and we will get back to you.

Okay
  Public Ticket #4001374
Banner Above Post
Open

Comments

  •  11
    LillaGreen started the conversation

    Hi there,

    Is there an easy way to implement a banner (not using JavaScript) that appears at the top of blog posts, but only within a specific category? I’d like to avoid showing it above all posts sitewide.  Or is it possible only with a snippet?

    Additionally, is there a way to display a sidebar banner only for posts in a certain category?

    I’d really appreciate any guidance on how to set this up.

    Thank you in advance

  •  2,855
    PenciDesign replied

    Hi,

    You should paste this code into the function.php of the child theme or via the CodeSnippet plugin here: https://wordpress.org/plugins/code-snippets/

    add_action( 'penci_action_before_the_content', function() {
        $post_id = get_the_ID();
        $post_categories = get_the_category( $post_id );
        $show_ads = false;
        $category_ids = [1, 2, 3]; // add category id here
        foreach ( $post_categories as $category ) {
            if ( in_array( $category->term_id, $category_ids ) ) {
                $show_ads = true;
                break;
            }
        }
        if ( $show_ads ) {
            echo '<div class="penci-ads">insert ad code here</div>';
        }
    });

    Regards,
    PenciDesign.

  •  11
    LillaGreen replied

    hi, thank yoi for your reply.The banner is not Google banner, it is from my customer and I want to place it only on certain categories on the top of a blog post as well as a sidebar. Ho to do it?

  •  2,855
    PenciDesign replied

    Hi,

    At this time, there is no available hook to insert content into a specific sidebar widget. You should manually add it via Appearance → Widgets.

    The previous code I sent will apply the ads code at the top of posts for specific category IDs.

    Regards,
    PenciDesign.