我的函数中有一组自定义主题设置。php文件。
In order to arrange some things I want to load jquery ONLY to my functions.php file.
我在wordpress中读到的是:
如果在admin中需要,可以使用admin\\u enqueue\\u scripts操作,however this enqueues it on ALL admin pages, which often leads to plugin/core conflicts, 最终打破了WordPress的管理体验。相反,您应该只在需要的单独页面上加载它,请参阅仅在插件页面上加载脚本部分以获取该示例。
这是wordpress推荐的脚本,用于仅在插件页面上启用jquery。
Can I adapt this script to enable my script just for the theme options page?
<?php
add_action( \'admin_init\', \'my_plugin_admin_init\' );
add_action( \'admin_menu\', \'my_plugin_admin_menu\' );
function my_plugin_admin_init() {
/* Register our script. */
wp_register_script( \'my-plugin-script\', plugins_url(\'/script.js\', __FILE__) );
}
function my_plugin_admin_menu() {
/* Register our plugin page */
$page = add_submenu_page( \'edit.php\', // The parent page of this menu
__( \'My Plugin\', \'myPlugin\' ), // The Menu Title
__( \'My Plugin\', \'myPlugin\' ), // The Page title
\'manage_options\', // The capability required for access to this item
\'my_plugin-options\', // the slug to use for the page in the URL
\'my_plugin_manage_menu\' // The function to call to render the page
);
/* Using registered $page handle to hook script load */
add_action(\'admin_print_styles-\' . $page, \'my_plugin_admin_styles\');
}
function my_plugin_admin_styles() {
/*
* It will be called only on your plugin admin page, enqueue our script here
*/
wp_enqueue_script( \'my-plugin-script\' );
}
function my_plugin_manage_menu() {
/* Output our admin page */
}
?>
谢谢大家!