dqw70970 2012-06-03 15:37
浏览 41
已采纳

仅在Wordpress中将CSS应用于“主题选项”页面

My current PHP code is working and styling my "Theme Options" page (located under the WP API Appearance menu) the way I want it to look, however...

The CSS stylesheet is also being applied to every other menu in the WP dashboard (such as affecting the "Settings > General-Options") page too. How am I able to go about applying the stylesheet just to my "Theme Options" page only and not tamper with anything else?

My stylesheet is named 'theme-options.css", located within a folder called "include" > include/theme-options.css. The code below is placed within a "theme-options.php" page.

<?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' );   
}   
  • 写回答

2条回答 默认 最新

  • drx3157 2012-06-03 16:40
    关注

    I was placing the CSS & JS files separately from the building blocks of my page (just above that function). The code is now inside my page build function and I am now getting the results I was after.

    Previously:

    ...
    // 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">
    
            ...
            ...
    

    Solution:

    // 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">
    
            ...
            ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了