• Resolved Sturek

    (@sturek)


    Hi,

    I’m hoping anyone can help me with this. I would like all the events in the calendar/list to link to a URL that I assign. I don’t want to have /events/event-title, but instead I would like to link the title etc to a URL that I assign, e.g. https://www.custom-url-com. I found this code, but where should I add it? Appreciate all help with this.

    <?php
    /*
     * This changes the event link to the event website URL if that is set.
     * NOTE: Comment out the add_filter() line to disable this function.
     */
    function tribe_set_link_website ( $link, $postId ) {
        $website_url = tribe_get_event_website_url( $postId );
        // Only swaps link if set
        if ( !empty( $website_url ) ) {
            $link = $website_url;
        }
        return $link;
    }
    add_filter( 'tribe_get_event_link', 'tribe_set_link_website', 100, 2 );
    /*
     * This changes the venue link to the venue website URL if that is set.
     * NOTE: Uncomment the add_filter() line to enable this function.
     */
    function tribe_set_venue_website ( $link, $postId, $display, $venue_url ) {
        $venue_link = tribe_get_venue_website_link( tribe_get_venue_id( $postId ) );
        // Only swaps link if set and full HTML <a> link is set
        if ( !empty( $venue_link ) ) {
            if ( $display ) {
                $link = $venue_link;
            } else {
                $venue_url = tribe_get_event_meta( tribe_get_venue_id( $postId ), '_VenueURL', true );
                $parseUrl  = parse_url( $venue_url );
                if ( empty( $parseUrl['scheme'] ) ) {
                    $venue_url = "<a href="https://$venue_url&quot" rel="nofollow">https://$venue_url&quot</a>;;
                }
                $link = $venue_url;
            }
        }
        return $link;
    }
    //add_filter( 'tribe_get_venue_link', 'tribe_set_venue_website', 100, 4 );
    /*
     * This changes the organizer link to the organizer website URL if that is set.
     * NOTE: Uncomment the add_filter() line to enable this function. As of PRO v3.9.1 not all organizer links are filterable.
     */
    function tribe_set_organizer_website ( $link, $postId, $echo, $url, $name ) {
        $organizer_link = tribe_get_organizer_website_link( tribe_get_organizer_id( $postId ), false);
        // Only swaps link if set
        if ( !empty( $organizer_link ) ) {
            $link = $organizer_link;
        }
        return $link;
    }
    //add_filter( 'tribe_get_organizer_link', 'tribe_set_organizer_website', 100, 5 );

    https://www.ads-software.com/plugins/the-events-calendar/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter Sturek

    (@sturek)

    The code was found on this page: https://gist.github.com/elimn/5bac70de00ec92804dc7

    Hey Sturek,

    That above snippet is three different options for modifying the event link. If you add it as is, the event link will be replaced with the link assigned to the website field for the event.

    If you would like a single link for all events, you can use that first function and remove the conditional for the $website_link check. You can then just replace $link value with the URL you would like the events to link to:
    `
    $link = ‘https://mysite.com&#8217;;

    Let me know if this helps.

    Thanks!

    Thread Starter Sturek

    (@sturek)

    Thanks for the reply!

    I would like the link to the event to be replaced with the link assigned to the website field for the event. All my events will have different links to the event sites. For achieving this I should only use this snippet.. right?

    function tribe_set_link_website ( $link, $postId ) {
        $website_url = tribe_get_event_website_url( $postId );
        // Only swaps link if set
        if ( !empty( $website_url ) ) {
            $link = $website_url;
        }
        return $link;
    }
    add_filter( 'tribe_get_event_link', 'tribe_set_link_website', 100, 2 );

    Sorry, but I still don’t understand where I should insert the code for doing this? Which .php-document should I open and insert the code?

    I would also really love to get help on this topic! ??

    Hey, Sturek, I just figured it out: you have to add it to the functions.php file from your theme.

    Paste the snippet just like you posted on your last comment. It’s already working on my website!

    Thread Starter Sturek

    (@sturek)

    Wow, thanks! It works =)

    Thanks!!

    I’d love to know too. Already brought down the site once by putting this code at the bottom of my functions.php file.

    Thread Starter Sturek

    (@sturek)

    I have put exactly this code in the bottom of the functions.php and it works. My site also went down, but that was because i had put <? php before the code below. Code should look exactly as below:

    function tribe_set_link_website ( $link, $postId ) {
        $website_url = tribe_get_event_website_url( $postId );
        // Only swaps link if set
        if ( !empty( $website_url ) ) {
            $link = $website_url;
        }
        return $link;
    }
    add_filter( 'tribe_get_event_link', 'tribe_set_link_website', 100, 2 );

    Sturkek,

    Thank you. It did work this time. The problem I had was that I too had put <?php in prior to the code you list above.

    I had copied all the code exactly as provided from the Events Calendar knowledgebase. Seems they should modify this. Might eliminate some trouble.

    Thanks again!

    Brook

    (@brook-tribe)

    Thanks for pointing that out Josh. The code in those tutorials is not encoded correctly, I will share this with the relevant parties and get it fixed. Cheers!
    – Brook

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Creating custom URL for an event in the calendar’ is closed to new replies.