【问题标题】:Wordpress theme from scratch从头开始的 WordPress 主题
【发布时间】:2017-12-18 07:14:37
【问题描述】:

我正在尝试从头开始开发一个 wordpress 主题,但我对 function.php 有一些问题。我想添加额外的样式脚本,如 bootstrap 和 animate.css,但问题是它们没有加载“包”,当我检查链接时,我在我的 css 文件夹之前得到 style.css。如果我删除 style.css,我可以在浏览器中查看我的文件。我该如何解决这个问题?从链接中删除 style.css。

http://localhost/humlan/wp-content/themes/humlan/style.css/css/bootstrap.min.css?ver=3.0.3'

这是 FUNCTION.PHP 中的代码

/**
 * Enqueue scripts and styles.
 */
function humlan_scripts() {
wp_enqueue_style( 'bootstrap.min', get_stylesheet_uri() . '/css/bootstrap.min.css',false,'3.0.3','all');
wp_enqueue_style( 'prettyPhoto', get_stylesheet_uri() . '/css/prettyPhoto.css',false,'1.1','all');
wp_enqueue_style( 'font-awesome.min', get_stylesheet_uri() . '/css/font-awesome.min.css',false,'1.1','all');
wp_enqueue_style( 'animate', get_stylesheet_uri() . '/css/animate.css',false,'1.1','all');
wp_enqueue_style( 'main', get_stylesheet_uri() . '/css/main.css',false,'1.1','all');
wp_enqueue_style( 'responsive', get_stylesheet_uri() . '/css/responsive.css',false,'1.1','all');
wp_enqueue_style( 'humlan-style', get_stylesheet_uri() );


    wp_enqueue_script( 'humlan-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );

    wp_enqueue_script( 'humlan-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}

add_action( 'wp_enqueue_scripts', 'humlan_scripts' );

【问题讨论】:

  • 这是 HEADER.PHP 中的代码 > gmpg.org/xfn/11">
  • 请仅对实际的 cmets 使用 添加评论 按钮。您应该 edit 您的原始问题以添加更多信息。

标签: php html css wordpress styles


【解决方案1】:

试试这个

function load_styles(){
   wp_enqueue_script( 'jQuery-js', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js');
   wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'), '3.3.7', true );
}

不要从你的服务器加载 css,而是使用相对更快的 CDN 链接......

【讨论】:

  • 是的!我同意你的看法,但现在我想使用下载的文件并使其与 wordpress 样式一起使用
【解决方案2】:

使用get_stylesheet_directory_uri() - 因为它会返回样式表的文件夹。您正在使用的返回 actual 样式表的 URI。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 2018-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多