Home › Forums › Calendar Products › Events Calendar PRO › Add a button to the event template
- This topic has 14 replies, 3 voices, and was last updated 9 years, 8 months ago by
playmakerne.
-
AuthorPosts
-
August 23, 2016 at 12:14 am #1154711
playmakerne
ParticipantHi,
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
ChristineAugust 23, 2016 at 2:58 pm #1155056Nico
MemberHi 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,
NicoAugust 25, 2016 at 12:45 am #1155683playmakerne
ParticipantThank 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
ChristineAugust 25, 2016 at 8:39 pm #1156185Nico
MemberSure 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,
NicoAugust 26, 2016 at 12:32 am #1156226playmakerne
ParticipantSorry. 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/
August 26, 2016 at 11:35 am #1156497Nico
MemberThanks!
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,
NicoAugust 30, 2016 at 4:25 am #1157484playmakerne
ParticipantWell, 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?
August 30, 2016 at 4:02 pm #1157867Nico
MemberThanks 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,
NicoAugust 31, 2016 at 12:20 am #1157978playmakerne
ParticipantThis snippet works well with my theme, as it links perfectly to tri.be π
August 31, 2016 at 6:32 pm #1158528Nico
MemberThanks 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,
NicoSeptember 1, 2016 at 4:15 am #1158672playmakerne
ParticipantYes, the link works now.
It looks like this: https://drive.google.com/file/d/0B09lyBqL_pARdEZreHBLb29mRVk/view?usp=sharing
Christine
September 1, 2016 at 8:56 am #1158790Nico
MemberPerfect, 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,
NicoSeptember 1, 2016 at 11:16 pm #1159132playmakerne
ParticipantIt 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
September 2, 2016 at 10:55 am #1159423Nico
MemberGlad 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 -
AuthorPosts
- The topic ‘Add a button to the event template’ is closed to new replies.
