最小 Wordpress Shortcode 插件示例
另请参见: 最小 WordPress JS 插件示例 最小 WordPress CSS 插件示例
此插件在 Wordpress 中创建一个简单的(静态 - 无参数)shortcode
首先,在 wp-content/plugins/ 中为你的插件创建一个目录,例如 wp-content/plugins/my-shortcode-plugin
将以下代码保存为插件文件夹中的 functions.php,例如 wp-content/plugins/my-shortcode-plugin/functions.php
my_shortcode_plugin.php
<?php
/*
Plugin Name: My shortcode plugin
*/
function my_shortcode( $atts , $content = null ) {
return '<h2>Shortcode works</h2>';
}
add_shortcode( 'my-shortcode', 'my_shortcode' );现在在你的 Wordpress 管理区域激活你的插件。
你现在可以创建包含此代码的文章或页面:
shortcode_usage.txt
[my-shortcode][/my-shortcode]它将像这样渲染:
shortcode_output.txt
Shortcode works
---------------If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow