A WordPress-centric search engine for devs and theme authors



rel_canonical ›

Since2.9.0
Deprecatedn/a
rel_canonical ( No parameters )
Defined at:
Codex:
Change Log:
  • 4.6.0

Outputs rel=canonical for singular queries.



Source

function rel_canonical() {
	if ( ! is_singular() ) {
		return;
	}

	$id = get_queried_object_id();

	if ( 0 === $id ) {
		return;
	}

	$url = wp_get_canonical_url( $id );

	if ( ! empty( $url ) ) {
		echo '<link rel="canonical" href="' . esc_url( $url ) . '" />' . "\n";
	}
}