_add_template_loader_filters

函式
_add_template_loader_filters ( No parameters )

_add_template_loader_filters: 這個函式用來給WordPress模板載入器系統新增過濾器。這些過濾器允許開發者修改由WordPress載入的特定主題或外掛的模板。

新增必要的過濾器,以使用’wp_template’文章而不是主題模板檔案。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _add_template_loader_filters() {
if ( ! current_theme_supports( 'block-templates' ) ) {
return;
}
$template_types = array_keys( get_default_block_template_types() );
foreach ( $template_types as $template_type ) {
// Skip 'embed' for now because it is not a regular template type.
if ( 'embed' === $template_type ) {
continue;
}
add_filter( str_replace( '-', '', $template_type ) . '_template', 'locate_block_template', 20, 3 );
}
// Request to resolve a template.
if ( isset( $_GET['_wp-find-template'] ) ) {
add_filter( 'pre_get_posts', '_resolve_template_for_new_post' );
}
}
function _add_template_loader_filters() { if ( ! current_theme_supports( 'block-templates' ) ) { return; } $template_types = array_keys( get_default_block_template_types() ); foreach ( $template_types as $template_type ) { // Skip 'embed' for now because it is not a regular template type. if ( 'embed' === $template_type ) { continue; } add_filter( str_replace( '-', '', $template_type ) . '_template', 'locate_block_template', 20, 3 ); } // Request to resolve a template. if ( isset( $_GET['_wp-find-template'] ) ) { add_filter( 'pre_get_posts', '_resolve_template_for_new_post' ); } }
function _add_template_loader_filters() {
	if ( ! current_theme_supports( 'block-templates' ) ) {
		return;
	}

	$template_types = array_keys( get_default_block_template_types() );
	foreach ( $template_types as $template_type ) {
		// Skip 'embed' for now because it is not a regular template type.
		if ( 'embed' === $template_type ) {
			continue;
		}
		add_filter( str_replace( '-', '', $template_type ) . '_template', 'locate_block_template', 20, 3 );
	}

	// Request to resolve a template.
	if ( isset( $_GET['_wp-find-template'] ) ) {
		add_filter( 'pre_get_posts', '_resolve_template_for_new_post' );
	}
}

常見問題

FAQs
檢視更多 >