Home › Forums › Calendar Products › Events Calendar PRO › Event detail page "URL" should contain target="_blank"
- This topic has 6 replies, 3 voices, and was last updated 7 years, 6 months ago by Cliff.
-
AuthorPosts
-
September 18, 2016 at 12:12 pm #1165658DinahParticipant
Hello,
the website link in the “details” section and also URLs that were added as an additional filed “URL” do not open the link in a new window, because target=”_blank” seems not to be set.
I tried to find a solution in the forum, but the only post I found (https://theeventscalendar.com/support/forums/topic/community-events-url-not-working/) was closed and I could not get the suggested JS snippet work.
I guess via editing the details.php in my child theme (…\wp-content\themes\mytheme-child-v1.0.0\tribe-events\modules\meta\details.php) I could make the link open up in a new window – is this correct?
// Event Website if ( ! empty( $website ) ) : ?> <dt> <?php esc_html_e( 'Website:', 'the-events-calendar' ) ?> </dt> <dd class="tribe-events-event-url"> <?php echo $website; ?> </dd> <?php endif ?>
For the additional fields it seems as if I would need to modify the original file “general.php” (..\wp-content\plugins\events-calendar-pro\src\functions\template-tags\general.php)
$meta = sprintf( '<a href="%s" target="%s">%s</a>', esc_url( $meta ), apply_filters( 'tribe_get_event_website_link_target', '_self' ), apply_filters( 'tribe_get_event_website_link_label', $url_label ) );
but I would like to avoid making any changes in the original files. Is there a way to make all Links open up in a new window? Or is there an option in the backend to toggle this on / off – maybe I haven’t found it yet?!
September 19, 2016 at 11:50 am #1166009CliffMemberHi Dinah.
You found the right code (good job!), but it seems you’re unaware how to use WordPress action and filter hooks (that’s ok).
The
apply_filters( 'tribe_get_event_website_link_target', '_self' ),
part of the code says to default to _self but allow this default to be overridden if you use the tribe_get_event_website_link_target filter.Here’s some example code to do just this (and a bit more – please read the code comments):
https://gist.github.com/cliffordp/3584b8aee70cde484700
Best practice for adding custom code (like to implement a PHP snippet to modify The Events Calendar) is to create a functionality plugin, unless it’s something specific to your theme, in which case best practice is to make sure you’re using a child theme, then add the customization to your child theme’s functions.php file.
I hope this information helps!
October 9, 2016 at 7:39 am #1174222DinahParticipantThank you very much, Cliff! That works 🙂
October 9, 2016 at 11:27 am #1174289DinahParticipantHi Cliff,
sorry I was too fast :-/ Unfortunately there is another problem now.
I pasted your code into my child-themes’ function.php and it really worked well – all links open up in a new window – as expected… BUT… each time I try to update a post in the wp backend the following error message appears:
Warning: Cannot modify header information – headers already sent by…
What did I do wrong? Or maybe did I misunderstand you in how to use your code?
October 9, 2016 at 11:37 am #1174294DinahParticipantSorry, my fault – I hadn’t pasted the code correctly into the functions.php. It is resolved.
October 10, 2016 at 7:38 am #1174491CliffMemberI’m glad to hear you got everything sorted out. 🙂
-
AuthorPosts
- The topic ‘Event detail page "URL" should contain target="_blank"’ is closed to new replies.