通过阅读教程,我创建了一个简单的快捷代码:
<?php
/*
Plugin Name: GT NoTranslate Shortcode
Description: Shortcode to wrap a span with the "notranslate" span around text.
Version: 0.1 BETA
Author: Andrew Truckle
Author URI: http://www.trucklesoft.co.uk
*/
function trucklesoft_gtspan_shortcode()
{
return \'<span class="notranslate">\' . $content . \'</span>\';
}
add_shortcode( \'ts\', \'trucklesoft_gtspan_shortcode\' );
?>
我已将代码放入
trucklesoft.php
然后把它放在一个叫做
trucklesoft
在
plugins
文件夹
我激活了插件。然而,当我编辑页面并将标题更改为:
[ts]This is the heading[/ts]
并预览它,它显示为:
[ts]This is the heading[/ts]
而不是
<span class="notranslate">This is the heading</span>
.
我做错了什么?
无论如何,我必须首先对代码进行更改,才能使其在页面内容中正常工作:
<?php
/*
Plugin Name: GT NoTranslate Shortcode
Description: Shortcode to wrap a span with the "notranslate" span around text.
Version: 0.1 BETA
Author: Andrew Truckle
Author URI: http://www.trucklesoft.co.uk
*/
function trucklesoft_gtspan_shortcode($atts, $content = null)
{
return \'<span class="notranslate">\' . $content . \'</span>\';
}
add_shortcode( \'ts\', \'trucklesoft_gtspan_shortcode\' );
?>
我最初尝试使用此插件的位置是标题。当我查看源时,它会显示在以下位置:
<header class="entry-header">
<h1 class="entry-title">Test</h1>
</header><!-- .entry-header -->