0

I'm working with Genesis Framework in a custom theme, but this is not a question "genesis-specific".

I need to populate the sidebar of my pages (not posts) conditionally. The condition is to check that it is not already populated by many other related functions (related news, related events, ad banners selected by the user from the backend...).

The actions I need to verify that have not been fired are: genesis_after_sidebar_widget_area and genesis_before_sidebar_widget_area. I'm trying to get it through playing with did_action().

I'm trying with this function:

add_action( 'genesis_after_sidebar_widget_area', 'understanding_did_action' );
function understanding_did_action() {
    if( did_action( 'genesis_after_sidebar_widget_area' ) > 0 || did_action( 'genesis_before_sidebar_widget_area' ) > 0 ) {
        echo '<h2>TESTING</h2>';
        echo 'before: ' . did_action( 'genesis_before_sidebar_widget_area' ) . '<br/>';
        echo 'after: ' . did_action( 'genesis_after_sidebar_widget_area' );
    }
}

and I always get: before: 1 & after: 1, even in the cases that nothing is printed in the sidebar or the action has been fired two or three times.

The point is to find the way to execute the function only when the values are less than "X" (1, 2, 3... it will depend).

Any ideas? Thanks

  • 1
    I may not be getting your fully, however do not you think that those actions always get called by the Genesis framework? I mean these are hook positions and they are always fired by genesis so that any functions tagged/hooked to those hooks will be called at those locations.. so it will always be 1 i.e. yes action hook was executed. – Mohsin May 20 '16 at 18:57
  • @Mohsin you put me on the right way. Indeed I was wrong trying to check the genesis hook doing it that way... I got it with "has_action" in spite of "did_action". Many thanks for your time! – Capiedge May 20 '16 at 19:36
  • Great! I have put the comment in the answer you make mark this question resolved! Good Luck! – Mohsin May 21 '16 at 11:27
0

Those actions always get called by the Genesis framework. I mean these are hook positions and they are always fired by genesis so that any functions tagged/hooked to those hooks will be called at those locations.. so it will always be 1 i.e. yes action hook was executed.

As discovered rightly by OP, using has_action instead of did_action did the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.