如何在php函数中调用自定义字体

问题描述 投票:0回答:1

我正在尝试在我的 WordPress 开发主题中添加自定义字体,但我在如何添加它时遇到了致命错误

/// Register fonts. Wp_register_style('font-awesome', get_stylesheet_uri(), [], filemtime get_template_directory_uri().'/fonts/font-awesome-webfont.woff', [], false, 'all'); wp_register_style('Naskh', get_stylesheet_uri(), [], filemtime get_template_directory_uri().'/fonts/naskh-webfont.woff', [], false, 'all'); wp_register_style('Roboto', get_stylesheet_uri(), [], filemtime, get_template_directory_uri().'/fonts/roboto-webfont.woff', [], false, 'all');

/// Enqueue Fonts. wp_enqueue_style('font-awesome-webfont.woff'); wp_enqueue_style('naskh-webfont.woff'); wp_enqueue_style('roboto-webfont.woff');

在CSS中我像这样添加它

--arabic-fonts:src='\\fonts\\naskh-webfont.woff'; --english-fonts:src='\\fonts\\roboto-webfont.woff';

[dir="rtl"] .container {font-family:var(--arabic-fonts);} [dir="ltr"] .container {font-family:var(--english-fonts);}

请帮助我谢谢您的回复我很感激

我尝试用 Google 搜索,但找不到任何可能的修复方法

这是我遇到的错误,抱歉

`Fatal error: Uncaught Error: Undefined constant "filemtime" in C:\xampp\htdocs\MyWebSite\wp-content\themes\Copper\functions.php:16 Stack trace: #0 C:\xampp\htdocs\MyWebSite\wp-includes\class-wp-hook.php(324): copper_enqueue_scripts('') #1 C:\xampp\htdocs\MyWebSite\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #2 C:\xampp\htdocs\MyWebSite\wp-includes\plugin.php(517): WP_Hook->do_action(Array) #3 C:\xampp\htdocs\MyWebSite\wp-includes\script-loader.php(2265): do_action('wp_enqueue_scri...') #4 C:\xampp\htdocs\MyWebSite\wp-includes\class-wp-hook.php(324): wp_enqueue_scripts('') #5 C:\xampp\htdocs\MyWebSite\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #6 C:\xampp\htdocs\MyWebSite\wp-includes\plugin.php(517): WP_Hook->do_action(Array) #7 C:\xampp\htdocs\MyWebSite\wp-includes\general-template.php(3050): do_action('wp_head') #8 C:\xampp\htdocs\MyWebSite\wp-content\themes\Copper\header.php(13): wp_head() #9 C:\xampp\htdocs\MyWebSite\wp-includes\template.php(810): require_once('C:\\xampp\\htdocs...') #10 C:\xampp\htdocs\MyWebSite\wp-includes\template.php(745): load_template('C:\\xampp\\htdocs...', true, Array) #11 C:\xampp\htdocs\MyWebSite\wp-includes\general-template.php(48): locate_template(Array, true, true, Array) #12 C:\xampp\htdocs\MyWebSite\wp-content\themes\Copper\index.php(7): get_header() #13 C:\xampp\htdocs\MyWebSite\wp-includes\template-loader.php(106): include('C:\\xampp\\htdocs...') #14 C:\xampp\htdocs\MyWebSite\wp-blog-header.php(19): require_once('C:\\xampp\\htdocs...') #15 C:\xampp\htdocs\MyWebSite\index.php(17): require('C:\\xampp\\htdocs...') #16 {main} thrown in C:\xampp\htdocs\MyWebSite\wp-content\themes\Copper\functions.php on line 16
There has been a critical error on this website.`

问题是 VS Code 在编辑器中没有显示任何错误

php html css wordpress fonts
1个回答
0
投票

当您像这里一样使用不带

$
的单词时
filemtime
PHP 将其视为常量,因此您需要先定义它。

该函数的第四个参数定义了脚本的版本。您可以设置 FALSE(这是默认行为)或首先定义常量。例如,在您尝试放置此代码的文件顶部:

define('VERSION', '1.0.0' );

然后

wp_register_style('Naskh', get_stylesheet_uri(), [], VERSION, get_template_directory_uri().'/fonts/naskh-webfont.woff', [], false, 'all');
© www.soinside.com 2019 - 2024. All rights reserved.