rest_output_link_wp_head

函数
rest_output_link_wp_head ( No parameters )

rest_output_link_wp_head: 这是一个WordPress的函数,在HTML头部部分为REST API响应输出一个链接头: 该函数接收一个链接数组,并将相应的链接头添加到HTML头部: 这个函数用于向客户提供额外的链接,可以用于分页或其他目的。

将REST API链接标签输出到页头。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function rest_output_link_wp_head() {
$api_root = get_rest_url();
if ( empty( $api_root ) ) {
return;
}
printf( '<link rel="https://api.w.org/" href="%s" />', esc_url( $api_root ) );
$resource = rest_get_queried_resource_route();
if ( $resource ) {
printf( '<link rel="alternate" type="application/json" href="%s" />', esc_url( rest_url( $resource ) ) );
}
}
function rest_output_link_wp_head() { $api_root = get_rest_url(); if ( empty( $api_root ) ) { return; } printf( '<link rel="https://api.w.org/" href="%s" />', esc_url( $api_root ) ); $resource = rest_get_queried_resource_route(); if ( $resource ) { printf( '<link rel="alternate" type="application/json" href="%s" />', esc_url( rest_url( $resource ) ) ); } }
function rest_output_link_wp_head() {
	$api_root = get_rest_url();

	if ( empty( $api_root ) ) {
		return;
	}

	printf( '<link rel="https://api.w.org/" href="%s" />', esc_url( $api_root ) );

	$resource = rest_get_queried_resource_route();

	if ( $resource ) {
		printf( '<link rel="alternate" type="application/json" href="%s" />', esc_url( rest_url( $resource ) ) );
	}
}

常见问题

FAQs
查看更多 >