【问题标题】:style.css not working in wordpressstyle.css 在 wordpress 中不起作用
【发布时间】:2014-01-31 11:43:28
【问题描述】:

我在使用 Wordpress 时遇到问题,我已经创建了所有需要的文件,包括 style.css index.php 等,但页面没有样式。在标题中,除其他外,我已经把这个

<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="text/css" href="<?php bloginfo('template_url'); ?>/css/style.css" />

【问题讨论】:

  • 您的目录是什么样的?解析后的 H​​TML 看起来如何?
  • 您是否注意到该链接(最后一行)中有两个 href 属性?

标签: css wordpress header styles stylesheet


【解决方案1】:

添加style.css以外的样式表,打开function.php并添加以下代码。

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
function theme_name_scripts() {
   wp_enqueue_style( 'style-name', get_stylesheet_uri() . "/css/bootstrap.css" );
   wp_enqueue_style( 'style-name', get_stylesheet_uri() . "/css/bootstrap-responsive.css" );
}

使用 Thins 添加 style.css 文件:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">

【讨论】:

  • wp_enqueue_style 中的样式名称,必须是唯一的。使用 add_action( 'wp_enqueue_scripts', 'theme_name_scripts' ); function theme_name_scripts() { wp_enqueue_style('style-name1', get_stylesheet_uri() . "/css/bootstrap.css" ); wp_enqueue_style('style-name2', get_stylesheet_uri() . "/css/bootstrap-responsive.css" ); }
【解决方案2】:

我遇到了同样的问题,但我通过仔细查看我的代码来解决它。这是我之前写的:

<link href="<?php bloginfo('stylesheet_url'); ?> rel="stylesheet" type="text/css" media="all" /> 

以及以下代码帮助我解决了问题:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">

你能看出区别吗?如果您有任何问题,请在下方评论。

【讨论】:

    【解决方案3】:

    将以下内容添加到您的functions.php,它应该可以工作。

    function EnqueueMyStyles() {
        wp_enqueue_style('my-custom-style', get_template_directory_uri() . '/css/my-custom-style.css', false, '20150320');
    
        wp_enqueue_style('my-google-fonts', '//fonts.googleapis.com/css?family=PT+Serif+Caption:400,400italic', false, '20150320');
    
        wp_enqueue_style('my-main-style', get_stylesheet_uri(), false, '20150320');
        }
    }
    add_action('wp_enqueue_scripts', 'EnqueueMyStyles');
    

    【讨论】:

    • 您的答案范围不正确。
    【解决方案4】:

    当您在 chrome 或某些浏览器上进行检查时,您的插件或 CSS 中也有 2 个站点 URL 或主页 URL。并在新标签中打开它(顺便说一句,这应该无法访问)::

    然后试着放

    "/" 在您的本地主机或其他任何内容中没有 "" > phpmyadmin > 数据库(WordPress 的)> wp_options >> option_value 中的 "siteurl" 和 "home"

    【讨论】:

    • 我的意思是你总是可以试试这个。如果它不起作用,很容易回去。我没有阅读你的问题。但这是我一直在寻找的解决方案,并找到了我自己的解决方案。只要记住一开始有什么。
    【解决方案5】:

    bloginfo 中将template_url 替换为template_directory 并完成如下操作:

    <link ... href="<?php bloginfo('template_directory'); ?>/css/bootstrap.css" />
    <link ... href="<?php bloginfo('template_directory'); ?>/style.css" />
    

    【讨论】:

      【解决方案6】:

      打开 function.php 文件并输入以下代码。

      add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
          function theme_name_scripts() {
             wp_enqueue_style( 'style-name1', get_stylesheet_uri() . "/css/style.css" );
             wp_enqueue_style( 'style-name2', get_stylesheet_uri() . "/css/bootstrap.css" );
      }
      

      【讨论】:

        【解决方案7】:

        functions.php 中添加此代码,它会将 style.css 文件链接到您的 WordPress 主题

        function load_scripts() {
            wp_enqueue_style( 'stylecss', get_stylesheet_uri() );  
        }
        
        add_action('wp_enqueue_scripts', 'load_scripts' );
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-03-03
          • 2012-06-05
          相关资源
          最近更新 更多