Hooks running before \'functions.php\'

Home Forums Welcome! Pre-Sales Questions Hooks running before \'functions.php\'

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1513536
    Luca
    Participant

    Hey guys, I tried to add some php-code to the single-event-view.
    I added an action to the hook ‘tribe_events_after_the_meta’ in my functions.php file.
    But nothing is happening. If I call the action in the functions.php directly, it works! (On the wrong position, of course.)

    So my guess is that the hook from the plugin fires before the “add_action” in my functions.php. I could be wrong, but still…

    Does anyone has an idea whats wrong?

    
    add_action( 'tribe_events_after_the_meta', 'addmycode' );
    
    function addmycode() {
    	echo "Hello world!";
    }
    
    #1515012
    Cliff
    Member

    Hi, Luca.

    Please reference https://theeventscalendar.com/knowledgebase/implementing-custom-code-snippets/ for how to implement custom code snippets.

    Please let me know how this goes for you.

    #1515480
    Luca
    Participant

    I’ve checked ALL of the tips in the article, nothing is wrong with anything mentioned there.

    What confuses me is, if I run the hook myself via do_action directly after my code on the functions.php it works perfectly as intended. But, as I mentioned earlier, on the wrong position.

    So I guess my code is not the problem. I just need to get my code running before the plugin code, maybe?

    #1515533
    Luca
    Participant

    Ok I managed it in a different way:

    add_action( 'loop_start', 'tribe_events_insertion' ); // Could also be "loop_end" for code AFTER the event
    function tribe_events_insertion() {
      if ( get_post_type( get_the_ID() ) == 'tribe_events' ) {
        // Extra Code		
      }
    }

    … if anyone else ever needs this …

    #1517210
    Cliff
    Member

    That hook is used in more than our own plugins — https://developer.wordpress.org/reference/hooks/loop_start/ — therefore, it’s likely not the ideal choice.

    Depending on what you’re trying to implement, you might be interested in using https://theeventscalendar.com/extensions/calendar-widget-areas/ — or at least reference its logic for which hook(s) to leverage.

    Another idea is to try https://wordpress.org/plugins/simply-show-hooks/ (third-party, not guaranteed or supported by us) to visually indicate where various hooks fire.

    Please let me know if you make any further progress for your needs.

    #1533933
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Hooks running before \'functions.php\'’ is closed to new replies.