wp_initialize_theme_preview_hooks

函数
wp_initialize_theme_preview_hooks ( No parameters )

添加过滤器和操作,以便在网站编辑器中启用区块主题预览。

过滤器和操作应在包含 `pluggable.php` 后添加,因为它们可能会触发使用 `current_user_can()`  的代码,而 `current_user_can()`  需要 `pluggable.php` 的功能。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_initialize_theme_preview_hooks() {
if ( ! empty( $_GET['wp_theme_preview'] ) ) {
add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
add_filter( 'template', 'wp_get_theme_preview_path' );
add_action( 'init', 'wp_attach_theme_preview_middleware' );
add_action( 'admin_head', 'wp_block_theme_activate_nonce' );
}
}
function wp_initialize_theme_preview_hooks() { if ( ! empty( $_GET['wp_theme_preview'] ) ) { add_filter( 'stylesheet', 'wp_get_theme_preview_path' ); add_filter( 'template', 'wp_get_theme_preview_path' ); add_action( 'init', 'wp_attach_theme_preview_middleware' ); add_action( 'admin_head', 'wp_block_theme_activate_nonce' ); } }
function wp_initialize_theme_preview_hooks() {
	if ( ! empty( $_GET['wp_theme_preview'] ) ) {
		add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
		add_filter( 'template', 'wp_get_theme_preview_path' );
		add_action( 'init', 'wp_attach_theme_preview_middleware' );
		add_action( 'admin_head', 'wp_block_theme_activate_nonce' );
	}
}

常见问题

FAQs
查看更多 >