分页: 1 / 1

wordpress block theme 添加自定义css

发表于 : 2023年 5月 28日 19:23
BobMaster
wordpress从版本5.9开始支持block theme,你可以使用各种区块构建自己的主题。

这篇帖子记录一下如何添加自定义css。
在主题目录下新建functions.php,内容如下

代码: 全选

<?php

if ( ! function_exists( 'qianxue_styles' ) ) :

    /**
     * Enqueue styles.
     */
    function qianxue_styles() {
            // Register theme stylesheet.
            $theme_version = wp_get_theme()->get( 'Version' );

            $version_string = is_string( $theme_version ) ? $theme_version : false;
            wp_register_style(
                    'qianxue-style',
                    get_template_directory_uri() . '/style.css',
                    array(),
                    $version_string
            );

            // Enqueue theme stylesheet.
            wp_enqueue_style( 'qianxue-style' );

    }

endif;

add_action( 'wp_enqueue_scripts', 'qianxue_styles' );

// Enqueue stylesheet in Editor
function qianxue_theme_setup() {
    add_editor_style( 'style.css' );
}
add_action( 'after_setup_theme', 'qianxue_theme_setup' );
函数名称可以改为你想要的。

参考链接: https://www.youtube.com/watch?v=Xz7uo1cFma0

Re: wordpress block theme 添加自定义css

发表于 : 2023年 5月 28日 22:42
ejsoon
我都用code snippets插件來添加css。