【问题标题】:Unable to load custom CSS on wordpress theme无法在 wordpress 主题上加载自定义 CSS
【发布时间】:2018-07-09 11:42:21
【问题描述】:

我已经创建了一个 HTML/CSS 设计,现在我正在尝试将其转换为 WordPress 模板。我已经创建了样式表和 function.php。

我的function.php中有以下代码

<?php

   function test_theme(){
    wp_enqueue_style("customstyle", get_stylesheet_uri() )



   }

add_action( 'wp_enqueue_scripts', 'test_theme' );

我已将此添加到我的 header.php 中

<?php wp_head(); ?>

由于某种原因,在添加 WordPress 后添加了一些脚本和链接到标题,但不是我的自定义样式表

我做错了什么?我也是 wordpress 开发和关注 youtube 视频的新手。

【问题讨论】:

标签: php wordpress wordpress-theming


【解决方案1】:

如何从头开始创建 wordpress 主题:

  1. 在 wp-content/themes/yourtheme 中创建您的主题文件夹
  2. 在您的主题文件夹中创建一个 index.php 文件
  3. 在主题文件夹中创建样式表 style.css
  4. 根据wordpress规则将你的代码放在index.php文件中

    <?php get_header(); echo "<h2>This is the index</h2>"; get_sidebar(); get_footer(); ?>

  5. 根据 wordpress 规则将 CSS 放在 style.css 中。通常我们将其添加到 style.css 的顶部,这样您就不必再将其排入 functions.php 中

/*
 * Theme Name: Your theme
 * Theme URI: https://yourtheme.com
 * Author: Memyself Andi
 * Author URI: https://yourtheme.com
 * Description: My WordPress theme.
 * Version: 1.0
*/

现在进入您的 wordpress 安装并转到仪表板 > 外观 > 主题 > 激活“您的主题”

【讨论】:

  • 我已经完成了所有这些。当我将样式添加到我的 index.php 中时,样式似乎有效,例如
    但当我使用 style.css 时无效
  • 我目前正在制作自己的主题,这始终是我的起始代码。它在 wordpress v 4.9.7 中运行没有任何问题。把你正在做的任何事情都剥离到基础上。然后在上面添加。
猜你喜欢
相关资源
最近更新 更多
热门标签