Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Plugin Name: Template Url ShortCode
Version: 0.1-alpha
Description: Template Url ShortCode
Author: kurozumi
Author URI:
Plugin URI:
Text Domain: template-url-shortcode
Domain Path: /languages
$tpl_url_shortcode = new TemplateUrlShortCode;
class TemplateUrlShortCode
public function register()
add_action('plugins_loaded', array($this, 'plugins_loaded'));
public function plugins_loaded()
// 新規投稿と投稿ページのみ反映
add_action('admin_head-post-new.php',array($this, 'add_mce_external_plugins'));
add_action('admin_head-post.php' ,array($this, 'add_mce_external_plugins'));
// ショートコード
add_shortcode('template_url', array($this, 'template_url'));
public function template_url()
// 子テーマに対応させるためget_stylesheet_directory_uri()を使う
return get_stylesheet_directory_uri();
function add_mce_external_plugins()
// ビジュアルリッチエディターの場合
if (get_user_option('rich_editing') == 'true') {
add_filter("mce_external_plugins", array($this, "mce_external_plugins"));
// 子テーマに対応させるためget_stylesheet_directory_uri()を使う
$tpl_url = get_stylesheet_directory_uri();
echo <<< EOF
<script type='text/javascript'>
var tpl_url = '{$tpl_url}';
// tinymceにエディタープラグインを追加する
public function mce_external_plugins()
$plugin_array['tpl_url_conv'] = plugin_dir_url(__FILE__) . 'tpl-url-editor-plugin.js';
return $plugin_array;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment