Add a button to the event template

Home Forums Calendar Products Events Calendar PRO Add a button to the event template

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1154711
    playmakerne
    Participant

    Hi,
    My employers would like to add a button to the top of each event. This button contains the word “TILMELD” (ENROL in Danish). When the putton is pushed, it must link to an external page for enrolment to events. We need the link to the external page, because unfortunately Event Tickets Plus doesn’t fit our special needs. Each event has its own link, and it should be easy to add this link, when an event is created.

    Is this even possible? I suppose it must be a change in the event template, if this shall work?

    I hope you can help me.
    Kind Regards
    Christine

    #1155056
    Nico
    Member

    Hi there Christine,

    Thank for getting in touch with us! I’ll help you getting this customization done πŸ™‚

    While you can create a template override for this, a snippet in the theme’s (or child theme’s) functions.php file might be a simple solution. You can add the ‘enrol’ URL in the event website link field in the back-end (https://cloudup.com/cCXu1_tszaT), the snippet below will grab that field value and create a link element in the single event page:

    /* Tribe, insert event website ask enrol link before event content */
    function tribe_enrol_link ( ){

    $website = tribe_get_event_website_url( );

    // bail if no website
    if ( empty( $website ) ) return false;

    echo 'TILMELD';
    }

    add_action( 'tribe_events_single_event_before_the_content', 'tribe_enrol_link');

    As the comments in the code indicate this will place the TILMELD link before the event content, please let me know if this works for you,
    Best,
    Nico

    #1155683
    playmakerne
    Participant

    Thank you for your response. I added the snippet to the functions.php and added the URL to an event. This does add the text “TILMELD” to the top of the event, but it doesn’t work as a link.

    You can see an example of what it looks like now at this link

    If it is possible my emplyers would prefer that it looks like a button (for instance similar to the SEARCH EVENTS button at the upper right corner of the event page: )

    Kind Regards
    Christine

    #1156185
    Nico
    Member

    Sure Christine, well get it to display nicely πŸ™‚

    Can you please follow-up with the event URL so I can check the mark-up generated by the snippet?

    Thanks,
    Nico

    #1156226
    playmakerne
    Participant

    Sorry. That’s strange. I did add them in my response – must have done something wrong. I’ll try again:

    Link to event: http://ny.playmakerne.dk/event/aalborg-bibliotekerne/

    Link to similar button (upper right corner): http://ny.playmakerne.dk/tilbud/

    #1156497
    Nico
    Member

    Thanks!

    I’m not sure why the text is showing without the link, it’s working as expected in my install πŸ™

    Can you please try this with a default WordPress theme (you’ll have to move the snippet to the correct functions file)? Can you try to put ‘google.com’ as the URL for the event?

    Regarding the style we can simulate something similar for sure, let’s get the link working and then we can look into it.

    Best,
    Nico

    #1157484
    playmakerne
    Participant

    Well, the link does work with the Twenty Sixteen theme from WordPress. I have changed the link to google.com as well. So how do you think I can solve the theme problem?

    #1157867
    Nico
    Member

    Thanks for following up Christine, and for testing this out in 2016 theme! Knowing that the snippet work with the default theme is a step forward to getting this solved πŸ™‚

    Can you try this modified version of the snippet with your theme?


    /* Tribe, insert event website ask enrol link before event content */
    function tribe_enrol_link ( ){
    echo 'TILMELD';
    }

    add_action( 'tribe_events_single_event_before_the_content', 'tribe_enrol_link');

    Hopefully this will help us narrow down what part of the snippet is not working as expected,
    Thanks,
    Nico

    #1157978
    playmakerne
    Participant

    This snippet works well with my theme, as it links perfectly to tri.be πŸ™‚

    #1158528
    Nico
    Member

    Thanks for confirming Christine! Let’s try to get closer to the complete snippet, please use this code now:


    /* Tribe, insert event website ask enrol link before event content */
    function tribe_enrol_link ( ){

    $website = tribe_get_event_website_url( );

    // bail if no website
    if ( empty( $website ) ) return false;

    // this line will print the website
    var_dump($website);

    $website = esc_attr( $website );

    // this line will print the website with escaped chars
    var_dump($website);

    echo 'TILMELD';
    }

    add_action( 'tribe_events_single_event_before_the_content', 'tribe_enrol_link');

    The above will print the configured website URL and the escaped website URL (which might be the same).

    Please let me know about the output and also if the link works this time,
    Thanks,
    Nico

    #1158672
    playmakerne
    Participant

    Yes, the link works now.

    It looks like this: https://drive.google.com/file/d/0B09lyBqL_pARdEZreHBLb29mRVk/view?usp=sharing

    Christine

    #1158790
    Nico
    Member

    Perfect, then just try this version of the final snippet:


    /* Tribe, insert event website ask enrol link before event content */
    function tribe_enrol_link ( ){

    $website = tribe_get_event_website_url( );

    // bail if no website
    if ( empty( $website ) ) return false;

    $website = esc_attr( $website );

    echo 'TILMELD';
    }

    add_action( 'tribe_events_single_event_before_the_content', 'tribe_enrol_link');

    I’m curious about why it didn’t work before, maybe it was just a copy/paste issue. Sometimes copying the code to a plain text editor helps out.

    Please let me know if it finally works now,
    Best,
    Nico

    #1159132
    playmakerne
    Participant

    It works perfectly, thank you.

    I did copy the snippet directly from the thread, so that might very well be the reason why it didn’t work in the first place.

    Christine

    #1159423
    Nico
    Member

    Glad to hear this works now Christine πŸ™‚

    Again, not sure why it wasn’t working in the first place, but stocked to see we could finally nail this!

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Have a great weekend,
    Nico

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Add a button to the event template’ is closed to new replies.