• 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

Use add_action conditionally for custom function

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 › Use add_action conditionally for custom function

This topic is: resolved

Tagged: add_action, conditionals

  • This topic has 6 replies, 3 voices, and was last updated 10 years, 5 months ago by SelenaD.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • February 9, 2016 at 7:48 pm #178698
    SelenaD
    Member

    I have a function that calls some custom fields. I want to add that function in a different place based on whether it's the home page, interior page, or blog page. So here's what I want to accomplish:

    function rm_some_function() {
       the_field('some_field');
    }
    
    function rm_position_some_function() {
    if(is_front_page()) {
      add_action('genesis_before_header', 'rm_some_function', 15);
    }
    if(is_home_page()) {
     add_action('genesis_after_header','rm_some_function', 15);
    } }
    
    add_action ('genesis_before_loop', 'rm_position_some_function');

    But it doesn't work. Any help would be appreciated.

    Thanks!

    February 9, 2016 at 9:18 pm #178701
    Christoph
    Member

    Hi,

    you have a typo.
    It´s is_home , not is_home_page.


    https://www.christophherr.com | Genesis Customizations | Buy me a coffee

    February 9, 2016 at 9:28 pm #178702
    SelenaD
    Member

    Thanks Christoph - but that isn't my issue. That's just my tired brain giving sample code in the forum. 🙁

    Here's real code:

    function rm_bio_box() { ?>
    	<div class="rm-bio-box"><div class="wrap">
        	<div class="rm-bio-image">
        		<?php the_field('bio_image', 'option'); ?>
    		</div>
            
            <div class="rm-bio-text-area">
              <div class="rm-bio-name">
                  <?php the_field('bio_name', 'option'); ?>
              </div>
              <div class="rm-bio-title">
                  <?php the_field('bio_title', 'option'); ?>
              </div>
              <div class="rm-bio-text">
                  <?php the_field('bio_text', 'option'); ?>
              </div>
            </div>
    	</div></div>
    <?php }
    
    function rm_bio_box_position() {
    	if(is_front_page()) {
    	add_action ('genesis_before_content_sidebar_wrap', 'rm_bio_box', 15);
    	}
    }
    add_action('genesis_before_loop', 'rm_bio_box_position');
    February 10, 2016 at 8:37 am #178736
    Victor Font
    Moderator

    Since this is an issue with ACF and not a Studio Press theme, you may be better off asking your question in the ACF forum. In any case, you may be using the_field incorrectly. http://www.advancedcustomfields.com/resources/the_field/


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 10, 2016 at 8:41 am #178737
    SelenaD
    Member

    Thanks Victor, but the ACF portion works just fine. The issue is ONLY with using the add_action as a conditional. It just so happens that I'm using ACF in this particular case.

    February 10, 2016 at 12:08 pm #178749
    Christoph
    Member

    Hi,

    genesis_before_loop "fires" after genesis_before_content_sidebar_wrap
    There is nothing "left" that it could add the action to.

    Try genesis_after_header instead of genesis_before_loop


    https://www.christophherr.com | Genesis Customizations | Buy me a coffee

    March 2, 2016 at 8:19 am #180441
    SelenaD
    Member

    Christoph, you're a saint. Knowing when things fire is a definite gap in my knowledge. It took me awhile to come back to this, but I am very grateful!

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and 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