我怎样才能把style.css最新文件?

时间:2014-01-30 16:35:35

标签: css wordpress

在wordpress中如何放置所有样式表文件的style.css最新文件?

我试过

function stylecssAlwaysLast() {
    wp_register_style( 'mystyle', get_stylesheet_directory_uri() .'/style.css');
    wp_enqueue_style( 'mystyle' );
}
add_action('wp_enqueue_scripts','stylecssAlwaysLast',1000);

最后添加文件,但不要删除style.css添加默认的wordpress代码。换句话说:在最后我有两个文件style.css: - (

更新

我懂了! : - )

目标:

  1. 删除默认主题style.css;
  2. 我的样式表必须是最新的项目;
  3. 如果存在,则压缩版本使用它代替默认版本;
  4. ......答案是......:

    function styleCompressedLatest() {
        // delete style.css
        wp_dequeue_style('wp-bootstrap');
        wp_deregister_style('wp-bootstrap');
    
        // text if exist compressed version
        if(file_exists(get_stylesheet_directory().'/style_compressed.css')) {
            $style = get_stylesheet_directory_uri() .'/style_compressed.css';
        } else {
            $style = get_stylesheet_directory_uri() .'/style.css';
        }
    
        // add my style.css
         wp_enqueue_style( 'mystyle', $style);
    }
    add_action('wp_enqueue_scripts','styleCompressedLatest',1000);
    

    有人知道最好的方法吗?

1 个答案:

答案 0 :(得分:1)

你走在正确的轨道上,只是不要打电话给你的样式表style.css,两者都将被包括在内。

此外,如果您只使用一次,则无需registerenqueue样式,只需使用wp_enqueue_style(),如下所示。

function stylecssAlwaysLast() {
    wp_enqueue_style( 'mystyle', get_stylesheet_directory_uri() .'/mystyle.css');
}
add_action('wp_enqueue_scripts','stylecssAlwaysLast',1000);
相关问题