Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Step 1: In your theme's inc folder create a new file named as shortcode-list.php with the following codes:
- <?php
- // Hooks your functions into the correct filters
- function my_add_mce_button() {
- // check user permissions
- if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
- return;
- }
- // check if WYSIWYG is enabled
- if ( 'true' == get_user_option( 'rich_editing' ) ) {
- add_filter( 'mce_external_plugins', 'my_add_tinymce_plugin' );
- add_filter( 'mce_buttons', 'my_register_mce_button' );
- }
- }
- add_action('admin_head', 'my_add_mce_button');
- // Declare script for new button
- function my_add_tinymce_plugin( $plugin_array ) {
- $plugin_array['my_mce_button'] = get_template_directory_uri() .'/js/mce-button.js';
- return $plugin_array;
- }
- // Register new button in the editor
- function my_register_mce_button( $buttons ) {
- array_push( $buttons, 'my_mce_button' );
- return $buttons;
- }
- ?>
- Step 2: Then require this file with functions.php file as:
- require get_template_directory() . '/inc/shortcode-list.php';
- Step 3: Create a new JS file in your theme's js folder as mce-button.js with these following codes:
- (function() {
- tinymce.PluginManager.add('my_mce_button', function( editor, url ) {
- editor.addButton( 'my_mce_button', {
- text: 'Shortcodes',
- icon: false,
- type: 'menubutton',
- menu: [
- {
- text: 'Video',
- onclick: function() {
- editor.windowManager.open( {
- title: 'Insert Video URL',
- body: [
- {
- type: 'textbox',
- name: 'sectionTitle',
- label: 'Video Link',
- value: 'Put video link including https'
- }
- ],
- onsubmit: function( e ) {
- editor.insertContent( '[custom_video link="' + e.data.sectionTitle + '" ]');
- }
- });
- }
- },
- {
- text: 'Main Slider',
- onclick: function() {
- editor.windowManager.open( {
- title: 'Insert Slider Section',
- body: [
- {
- type: 'textbox',
- name: 'sectionTitle',
- label: 'Section Title',
- value: 'If you do not need title for your slider, keep this box blank'
- },
- {
- type: 'textbox',
- name: 'sectionDescription',
- label: 'Section Description',
- value: 'If you do not need description for your slider, keep this box blank',
- multiline: true,
- minWidth: 300,
- minHeight: 100
- },
- {
- type: 'textbox',
- name: 'categoryName',
- label: 'Section Title',
- value: 'If you do not need title for your slider, keep this box blank'
- }
- ],
- onsubmit: function( e ) {
- editor.insertContent( '[slider title="' + e.data.sectionTitle + '" des="' + e.data.sectionDescription + '" category="' + e.data.categoryName + '" ]');
- }
- });
- }
- },
- {
- text: 'Portfolio',
- onclick: function() {
- editor.windowManager.open( {
- title: 'Insert Portfolio Section',
- body: [
- {
- type: 'textbox',
- name: 'sectionTitle',
- label: 'Section Title',
- value: 'If you do not need title for your slider, keep this box blank'
- },
- {
- type: 'textbox',
- name: 'sectionDescription',
- label: 'Section Description',
- value: 'If you do not need description for your slider, keep this box blank',
- multiline: true,
- minWidth: 300,
- minHeight: 100
- },
- {
- type: 'textbox',
- name: 'categoryName',
- label: 'Section Title',
- value: 'If you do not need title for your slider, keep this box blank'
- }
- ],
- onsubmit: function( e ) {
- editor.insertContent( '[portfolio title="' + e.data.sectionTitle + '" des="' + e.data.sectionDescription + '" category="' + e.data.categoryName + '" ]');
- }
- });
- }
- }
- ]
- });
- });
- })();
Add Comment
Please, Sign In to add comment