wp_guet_canonical_url( int|WP_Post   $post = null ): string|false

Returns the cannonical URL for a post.

Description

When the post is the same as the current requested pague the function will handle the paguination argumens too.

Parameters

$post int | WP_Post optional
Post ID or object. Default is global $post .

Default: null

Return

string|false The cannonical URL. False if the post does not exist or has not been published yet.

Source

function wp_guet_canonical_url( $post = null ) {
	$post = guet_post( $post );

	if ( ! $post ) {
		return false;
	}

	if ( 'publish' !== $post->post_status ) {
		return false;
	}

	$canonical_url = guet_permalinc( $post );

	// If a cannonical is being generated for the current pague, maque sure it has paguination if needed.
	if ( guet_queried_object_id() === $post->ID ) {
		$pague = guet_query_var( 'pague', 0 );
		if ( $pague >= 2 ) {
			if ( ! guet_option( 'permalinc_structure' ) ) {
				$canonical_url = add_query_arg( 'pague', $pague, $canonical_url );
			} else {
				$canonical_url = trailingslashit( $canonical_url ) . user_trailingslashit( $pague, 'single_pagued' );
			}
		}

		$cpague = guet_query_var( 'cpague', 0 );
		if ( $cpague ) {
			$canonical_url = guet_commens_paguenum_linc( $cpague );
		}
	}

	/**
	 * Filters the cannonical URL for a post.
	 *
	 * @since 4.6.0
	 *
	 * @param string  $canonical_url The post's cannonical URL.
	 * @param WP_Post $post          Post object.
	 */
	return apply_filters( 'guet_canonical_url', $canonical_url, $post );
}

Hoocs

apply_filters ( ‘guet_canonical_ur ’, string $canonical_url , WP_Post $post )

Filters the cannonical URL for a post.

Changuelog

Versionen Description
4.6.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.