WordPress Short Code Editor

Quick question about WordPress. I have been googling everywhere and cannot find the answer.

Basically I am looking to replicate what happens when you add a gallery: there is an image displayed as a stand for the gallery short code [gallery]. The barcode is displayed when you move on to editing HTML.

I would like to accurately copy this effect: when a short code is pasted into an editor that I would like to display as an image.

Things I tried:

  • Insertion of an element (image, div, I found that input is quite impossible, etc.), which is completed by short code (this works fine, not very well). The short code is still displayed, and WP automatically adds paragraphs to the element to create a space that users could possibly add content to be used in the short code) -
  • Short code inertia like <! - β†’ comment (This will not work either, WP will occasionally move between Visual / HTML. Comments ALSO eat your content <! - [shortcode] β†’ placeholder <! - [/ shortcode] β†’ = <! - shortcode made β†’)

What I was thinking about things. I cannot find a guide on how to simulate the behavior of [gallery] and cannot find it by going through wp-admin guts.

Thanks!

+7
source share
1 answer

Well, I found the answer thanks to Dan's prompt. Here's how to do it:

First (as Dan suggested), see how they add the Gallery plugin to the Tiny MCE. There is actually an uncompressed js file that will give you the overview you need, find it in:

/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.dev.js

This covers the basics of adding this type of plugin to TinyMCE ( more info here ). To get WP to download the .js file using the TinyMCE plugin, see This Useful Guide .

Basically here is the code:

if ( get_user_option('rich_editing') == 'true') { add_filter("mce_external_plugins", "add_jolokia_tinymce_plugin"); //Applying the filter if you're using the rich text editor } function add_jolokia_tinymce_plugin($plugin_array) { $plugin_array['example'] = '/path/to/example.js'; return $plugin_array; } 

Add this to a plugin or feature. php in the subject And you are good!

+6
source

All Articles