Event detail page "URL" should contain target="_blank"

Home Forums Calendar Products Events Calendar PRO Event detail page "URL" should contain target="_blank"

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1165658
    Dinah
    Participant

    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?!

    #1166009
    Cliff
    Member

    Hi 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!

    #1174222
    Dinah
    Participant

    Thank you very much, Cliff! That works 🙂

    #1174289
    Dinah
    Participant

    Hi 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?

    #1174294
    Dinah
    Participant

    Sorry, my fault – I hadn’t pasted the code correctly into the functions.php. It is resolved.

    #1174491
    Cliff
    Member

    I’m glad to hear you got everything sorted out. 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Event detail page "URL" should contain target="_blank"’ is closed to new replies.