• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Exclude Blog Page when Adding an Action / Remove Action from Blog Page (NewsPro)

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Exclude Blog Page when Adding an Action / Remove Action from Blog Page (NewsPro)

This topic is: resolved

Tagged: Add Action, condition, identify blog page, remove action

  • This topic has 2 replies, 2 voices, and was last updated 8 years, 1 month ago by nici-.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • January 11, 2018 at 9:08 am #215297
    nici-
    Member

    Hi,

    I need to remove an action from the blog page of NewsPro theme. Therefor I need a condition in function.php to identify this page. Or - even better: A condition with which I can add my action ONLY to the single view of posts.

    What I have done and want to do:

    I use NewsPro theme here:
    https://shopanbieter.de/relaunch

    I added an action that displays a random sponsor ad into the blog posts hooked into 'genesis_before_entry_content'. So far so good:

    ************
    // zufällige Sponsor-Ad in die Posts - physalia.de
    add_action( 'genesis_before_entry_content', 'SponsorAds' );
    function SponsorAds() {

    global $post;
    if($post->post_type == 'post'){

    print random_file_content(ABSPATH . "SponsorAds");}
    }

    function random_file_content($dir)
    {
    $files = scandir($dir); # since php5
    $files = array_diff($files, [".", ".."]);

    $key = array_rand($files);
    $file = $files[$key];
    return file_get_contents($dir."/".$file);
    }
    **************

    To prevent the ads from the posts of one special category, I removed the action this way:

    **************

    // zufällige Sponsor-Ad NICHT in Sponsored Posts-Kategorie - physalia.de
    function NoSponsorAd( $query ) {
    if ( $query->is_single() ) {
    $query->set( 'cat', '-21' );//add your category number
    }
    return $query;
    }
    remove_action( 'genesis_before_entry_content', 'SponsorAds' );

    **************

    Also ok.

    Now I created the blog page:
    https://www.shopanbieter.de/relaunch/news/
    (like in the manual this is an empty page with template "Blog")

    Unfortunately the ads show in this page! I do NOT want the ads here. So first I tried to also check for single view in the condition when adding the action - but to no avail.

    I Asked the support, they sent me this code to remove the action, but this does NOT work:

    **********
    // unhook SponsorAds only when page with blog page template is in use
    add_action( 'get_header', 'remove_SponsorAds_blog_page' );
    function remove_SponsorAds_blog_page() {
    if ( is_page_template(page_blog-php) ) {
    remove_action( 'genesis_before_entry_content', 'SponsorAds' );
    }
    }
    **********

    Pity!

    So I tried to check on the single template when adding the action:

    **********
    add_action( 'genesis_before_entry_content', 'SponsorAds' );
    function SponsorAds() {

    global $post;
    if($post->post_type == 'post' && is_page_template('single.php') ){

    print random_file_content(ABSPATH . "SponsorAds");}
    }
    **********

    Still the ads are shown in the blog page:
    https://www.shopanbieter.de/relaunch/news/

    Question:
    How can I remove the ads here (or even better not add them there in the first place)? All hints are appreciated.

    (I've just started with Genesis framework and are a bit weak in skills so far - but learning quickly I hope).

    Best regards
    nici-

    https://www.shopanbieter.de/relaunch/news/
    January 11, 2018 at 10:11 am #215299
    Marcy
    Participant

    The conditional for the blog page template is:

    if ( genesis_is_blog_template() ) {
    ...
    }

    Marcy | Amethyst Website Design | Twitter

    January 15, 2018 at 3:00 pm #215430
    nici-
    Member

    Great, thanks a lot!

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Exclude Blog Page when Adding an Action / Remove Action from Blog Page (NewsPro)’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble