tribe_get_event_link( WP_Post|int|null $post_id = null, bool $full_link = false )

Retrieves the link to a single event.

This function returns the URL to a single event post, or if the $full_link parameter is set to true, it outputs a complete HTML <a> tag with the event title as the link text. If no event is found, it returns false.


Parameters

$post_id

(WP_Post|int|null) (Optional) The event post ID or WP_Post object. Defaults to the current post if not provided.

Default value: null

$full_link

(bool) (Optional) If true, outputs a complete HTML <a> tag. Defaults to false, returning just the URL.

Default value: false


Top ↑

Return

(string|false) The URL to the event or an HTML <a> tag if $full_link is true. Returns false if no link is found.


Top ↑

Source

File: src/functions/template-tags/link.php

	function tribe_get_event_link( $post_id = null, $full_link = false ) {
		$post_id = Tribe__Main::post_id_helper( $post_id );
		$url = Tribe__Events__Main::instance()->getLink( 'single', $post_id );

		if ( '' != get_option( 'permalink_structure' ) ) {
			$url = trailingslashit( $url );
		}

		if ( $full_link ) {
			$title_args = array( 'post' => $post_id, 'echo' => false );
			$name       = get_the_title( $post_id );
			$attr_title = the_title_attribute( $title_args );
			$link       = false;

			if ( ! empty( $url ) && ! empty( $name ) ) {
				$link = sprintf(
					'<a href="%1$s" title="%2$s"">%3$s</a>',
					esc_url( $url ),
					$attr_title,
					$name
				);
			}
		} else {
			$link = $url;
		}

		/**
		 * Filters the permalink to events
		 *
		 * @param mixed  $link      The link, possibly HTML, just URL, or false
		 * @param int    $post_id   Post ID
		 * @param bool   $full_link Whether to output full HTML <a> link
		 * @param string $url       The URL itself
		 */
		return apply_filters( 'tribe_get_event_link', $link, $post_id, $full_link, $url );
	}

Top ↑

Changelog

Changelog
Version Description
2.0.1 Introduced.