Short Code plugin for WordPress
2011-09-29 00:52
309 查看
为 WordPress 开发了一个 Short Code 插件, 灰常简单, 编辑内容时输入 [[content, tip]] 就可以在正文中显示漂亮的 tooltip 效果.
效果实现使用了一个 jQuery 插件: http://docs.jquery.com/Plugins/Tooltip
插件代码如下:
shortcode.php
shortcode.js
效果实现使用了一个 jQuery 插件: http://docs.jquery.com/Plugins/Tooltip
插件代码如下:
shortcode.php
<?php /* Plugin Name: Short Code Plugin URI: http://blog.csdn.net/dofy/article/details/6832357 Description: Short code!! e.g. [[content,<strong>Here</strong> is the tips...]] Version: 1.0 Author: Seven Yu Author URI: http://www.douban.com/people/dofy/ */ function add_js() { wp_register_script('simpletip', plugins_url('/jquery.tooltip.min.js', __FILE__)); wp_enqueue_script('simpletip'); wp_register_script('shortcode', plugins_url('/shortcode.js', __FILE__)); wp_enqueue_script('shortcode'); } function add_css() { wp_enqueue_style('shortcode', plugins_url('/jquery.tooltip.css', __FILE__)); } /** * 替换内容 * [[content,tips]] */ function shortcode($content) { $reg = '#\[\[([^,]+)\,(.+)\]\]#'; return preg_replace_callback($reg, 'replace_code', $content); } function replace_code($matches) { return sprintf('<span class="shortcode" title="%2$s">%1$s</span>', $matches[1], htmlspecialchars($matches[2])); } add_action('wp_print_styles', 'add_css'); add_action('wp_print_scripts', 'add_js'); add_filter('the_content', 'shortcode'); ?>
shortcode.js
/** * Short Code * Author: Seven Yu */ (function($) { $(function() { $('.shortcode').tooltip(); }); })(jQuery);
相关文章推荐
- [PHP] create plugin and short code in WordPress
- Vundle is short for Vimbundle and is a Vim plugin manager.
- Code Syntax Highlighter Plugin for TiddlyWiki
- FCKeditor基于SyntaxHighlighter 的代码语法高亮插件(Code Syntax Highlight Plugin for FCKeditor)
- wordpress使用短代码(Shortcode)插入优酷,土豆视频支持ios
- WordPress Shortcode(短代码):完全指南
- The parameters 'mainClass' for goal org.codeh aus.mojo:exec-maven-plugin:1.6.0:java are missing or
- WordPress中的shortcode短代码功能使用详解
- Nivo Slider for jquery and wordpress plugin
- jquery crossdomain post plugin i changed bit test code suite for my env,due to the windows env is not familiar with github operation,i didn't forked form the original resposeritoy
- Format Fortran Indent Plugin for Code::Blocks
- 如何启动plugin for editing C++ code
- Bytecode Outline plugin for Eclipse
- WordPress中的shortcode短代码功能使用详解
- How to Use the Format Fortran Indent Plugin for Code::Blocks ?
- 才知道 Windows Live Writer Source Code plugin for SyntaxHighlighter 更新到2.0了
- WordPress Woopra plugin remote PHP arbitrary code execution exploit.
- Keyword Insertion Plugin For Wordpress
- WordPress Shortcode(简码)介绍及使用详解
- test Source Code plugin for SyntaxHighlighter