post

WordPress 外观编辑中显示js、html等文件

WordPress后台编辑主题文件中,默认只能编辑php和css文件,但是可以通过简单地更改theme-editor.php源代码支持编辑js、html、txt等文件。下面就介绍下,如何在WordPress外观编辑主题中增加显示其他的文件类型。

先看下效果图:

WordPress编辑主题js文件

在wp-admin/theme-editor.php,找到以下代码:

$allowed_files = $theme->get_files( 'php', 1 );
$has_templates = ! empty( $allowed_files );
$style_files = $theme->get_files( 'css' );
$allowed_files['style.css'] = $style_files['style.css'];
$allowed_files += $style_files;

简单的解释一下,这几句代码旨在限定theme-editor(主题编辑)中允许出现的文件类型,这样一来就很好办咯。

以添加js为例,在上述代码后面增加如下代码:

$js_files = $theme->get_files( 'js' );
$allowed_files += $js_files;

如果添加html、txt等文件,同样先定义变量,然后在$allowed_files变量后追加即可。

请注意:只有根目录下的文件才会显示。

文章来源于:小蝴蝶

Comments

  1. 这是不错的技巧

  2. 这是不错的技巧

Speak Your Mind

*

· 223 次浏览