首页 文章

如何在将HTML模板转换为wordpress主题时链接style.css文件

提问于
浏览
1

我有一个HTML模板,我想将其转换为Wordpress主题 . WordPress主题需要style.css和index.php才能工作,但模板没有csse文件,它有一个css文件夹 . 我该如何链接?

2 回答

  • 0

    你可以使用 get_template_directory_uri() 功能 .

    例如:

    <link rel="stylesheet" href="<?php echo get_template_directory_uri();?>/css/style.css" />

  • 1

    将它放在 Headers 中将正常工作 . 这里's the '正确的方法在Wordpress上执行 - 以下内容在您的functions.php文件或custom plugin中 .

    function thatwomanuk_header_scripts()
    {
        // My stylesheet
        wp_register_style('mystyles', get_template_directory_uri().'/css/style.css', array(), '1.0', 'all');
        wp_enqueue_style('mystyles');
    }
    
    add_action('init', 'thatwomanuk_header_scripts'); // Add Custom Scripts to wp_head
    

    样式表和javascripts的参数是:名称/句柄,源,类型,数组(依赖项),版本,延迟 . 最后的“全部”是该样式表的媒体查询 - 例如,它可能是“屏幕”或“打印” .

    更多信息在这里,以及其他地方:http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/

相关问题