function rel_canonical() { if ( !is_singular() ) return; global $wp_the_query; if ( !$wp_the_query->get_queried_object_id() ) return; $link = get_permalink( $wp_the_query->get_queried_object_id() ); echo "\n"; } add_action( 'wp_head', 'rel_canonical' );