但是,我当前的PHP代码正在工作,我的“主题选项”页面(位于WP API外观菜单下)的样式是我想要的.
CSS样式表也被应用于WP仪表板中的每个其他菜单(例如影响“设置>常规-选项”)页面。我如何才能将样式表仅应用于我的“主题选项”页面,而不篡改其他任何内容?
我的样式表名为‘Them-options.css’,位于一个名为"include“>include/hem-options.css的文件夹中。下面的代码放在一个”Top-options.php“页面中。
<?php
// Add our CSS Styling
add_action( 'admin_menu', 'admin_enqueue_scripts' );
function admin_enqueue_scripts() {
wp_enqueue_style( 'theme-options', get_template_directory_uri() . '/include/theme-options.css' );
wp_enqueue_script( 'theme-options', get_template_directory_uri() . '/include/theme-options.js' );
} 发布于 2012-06-03 16:40:31
我将CSS & JS文件与页面的构建块分开放置(就在该函数之上)。代码现在是I,我的页面构建函数,现在我得到了我想要的结果。
以前:
...
// Add our CSS Styling
function theme_admin_enqueue_scripts( $hook_suffix ) {
wp_enqueue_style( 'theme-options', get_template_directory_uri() . '/include/theme-options.css', false, '1.0' );
wp_enqueue_script( 'theme-options', get_template_directory_uri() . '/include/theme-options.js', array( 'jquery' ), '1.0' );
// Build our Page
function build_options_page() {
ob_start(); ?>
<div class="wrap">
<?php screen_icon();?>
<h2>Theme Options</h2>
<form method="post" action="options.php" enctype="multipart/form-data">
...
...解决方案:
// Build our Page
function build_options_page() {
// Add our CSS Styling
wp_enqueue_style( 'theme-options', get_template_directory_uri() . '/include/theme-options.css' );
wp_enqueue_script( 'theme-options', get_template_directory_uri() . '/include/theme-options.js' );
ob_start(); ?>
<div class="wrap">
<?php screen_icon();?>
<h2>Theme Options</h2>
<form method="post" action="options.php" enctype="multipart/form-data">
...
...发布于 2012-06-03 15:50:03
只有在当前页是检查页面以前的特殊页面时,才能添加css文件,例如:
if (is_page('Theme Options')) { // check post_title, post_name or ID here
add_action( 'admin_menu', 'admin_enqueue_scripts' );
}===更新===
也许更好的方法是签入函数:
<?php
// Add our CSS Styling
add_action( 'admin_menu', 'admin_enqueue_scripts' );
function admin_enqueue_scripts() {
if (is_page('Theme Options')) { // check post_title, post_name or ID here
wp_enqueue_style( 'theme-options', get_template_directory_uri() . '/include/theme-options.css' );
}
wp_enqueue_script( 'theme-options', get_template_directory_uri() . '/include/theme-options.js' );
} https://stackoverflow.com/questions/10871651
复制相似问题