Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Wordpress插件中包含自定义字体文件_Php_Wordpress_Fonts - Fatal编程技术网

Php 在Wordpress插件中包含自定义字体文件

Php 在Wordpress插件中包含自定义字体文件,php,wordpress,fonts,Php,Wordpress,Fonts,是否可以在Wordpress插件中包含自定义字体、文件和所有内容 假设插件目录为wp content/plugins/my plugin/ 因此,我将字体添加到wp content/plugins/my plugin/fonts/font.ttf中 现在我如何访问插件css文件中的自定义字体 @font-face { font-family: 'my-font'; src: url(wp-content/plugins/my-plugin/fonts/my-font.ttf);

是否可以在Wordpress插件中包含自定义字体、文件和所有内容

假设插件目录为wp content/plugins/my plugin/ 因此,我将字体添加到wp content/plugins/my plugin/fonts/font.ttf中 现在我如何访问插件css文件中的自定义字体

@font-face {
  font-family: 'my-font';  
  src: url(wp-content/plugins/my-plugin/fonts/my-font.ttf);  
  font-weight: normal;  
}

似乎不起作用。如何实现这一点?

通常插件开发人员使用当前目录路径和URL分别定义一个常量,如
plugin\u DIR\u PATH
plugin\u DIR\u URL
,其中
plugin
可以是插件的名称,以使其唯一。说你的插件名为示例

define( 'EXAMPLE_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'EXAMPLE_DIR_URL', plugin_dir_url( __FILE__ ) );
但在您的情况下,我们只需要
示例\u DIR\u URL
。现在,在插件的任何地方,如果您需要引用任何资源,只需使用
EXAMPLE\u DIR\u URL
作为基础。就你而言

@font-face {
  font-family: php'my-font';  
  src: url(<?= EXAMPLE_DIR_URL; ?>'/fonts/my-font.ttf);  
  font-weight: normal;  
}
@font-face{
字体系列:php'my-font';
src:url('/fonts/my-font.ttf);
字体大小:正常;
}

通常插件开发人员使用当前目录路径和URL分别定义一个常量,如
plugin\u DIR\u PATH
plugin\u DIR\u URL
,其中
plugin
可以是插件的名称,以使其唯一。说你的插件名为示例

define( 'EXAMPLE_DIR_PATH', plugin_dir_path( __FILE__ ) );
define( 'EXAMPLE_DIR_URL', plugin_dir_url( __FILE__ ) );
但在您的情况下,我们只需要
示例\u DIR\u URL
。现在,在插件的任何地方,如果您需要引用任何资源,只需使用
EXAMPLE\u DIR\u URL
作为基础。就你而言

@font-face {
  font-family: php'my-font';  
  src: url(<?= EXAMPLE_DIR_URL; ?>'/fonts/my-font.ttf);  
  font-weight: normal;  
}
@font-face{
字体系列:php'my-font';
src:url('/fonts/my-font.ttf);
字体大小:正常;
}

plugin文件夹中的.css文件中是否有@font字体?如果是这样的话,它似乎不起作用。使用一个动作将它输出到
wp\u head
。我是否将@font-face放入插件文件夹中的.css文件中?如果是这样,它似乎不起作用,使用动作将其输出到
wp\u head