wp_maybe_load_widgets

函式
wp_maybe_load_widgets ( No parameters )

wp_maybe_load_widgets: 這個函式用來載入widgets在頁面上工作所需的檔案。它檢查頁面上是否有任何widgets被使用,然後載入所需的指令碼和樣式。

確定是否應該載入Widgets庫。

檢查以確保widgets庫還沒有被載入。如果還沒有,那麼它將載入widgets庫並執行一個動作鉤。

function wp_maybe_load_widgets() {
	/**
	 * Filters whether to load the Widgets library.
	 *
	 * Returning a falsey value from the filter will effectively short-circuit
	 * the Widgets library from loading.
	 *
	 * @since 2.8.0
	 *
	 * @param bool $wp_maybe_load_widgets Whether to load the Widgets library.
	 *                                    Default true.
	 */
	if ( ! apply_filters( 'load_default_widgets', true ) ) {
		return;
	}

	require_once ABSPATH . WPINC . '/default-widgets.php';

	add_action( '_admin_menu', 'wp_widgets_add_menu' );
}

常見問題

FAQs
檢視更多 >