Wordpress 4.1 TinyMce Button Plugin


Rexspi

I'm trying to add a button on tinymce editor in wordpress

WordPress version: 4.1

I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182

But it doesn't work. I've at least googled the assignment and I've tried to find something but no results.

Anyone know what's wrong with the tutorial?

All I want to do is add a button on tinymce that takes the youtube url and add a custom html with a link where the cursor is.

Thank you in advance, I'm really new to php, wordpress and tinymce.

edit:

Try the tutorial link suggested by @Kaloyan Ivanov : https://www.gavick.com/blog/wordpress-tinymce-custom-buttons

My steps:

1. I added the first 4 php codes at the end of the theme's functions.php

        //add custom plugin to tinymce
        add_action('admin_head', 'gavickpro_add_my_tc_button');

        function gavickpro_add_my_tc_button() {
            global $typenow;
            // check user permissions
            if ( !current_user_can('edit_posts') && !current_user_can('edit_pages') ) {
            return;
            }
            // verify the post type
            if( ! in_array( $typenow, array( 'post', 'page' ) ) )
                return;
            // check if WYSIWYG is enabled
            if ( get_user_option('rich_editing') == 'true') {
                add_filter("mce_external_plugins", "gavickpro_add_tinymce_plugin");
                add_filter('mce_buttons', 'gavickpro_register_my_tc_button');
            }
        }

        function gavickpro_add_tinymce_plugin($plugin_array) {
            $plugin_array['gavickpro_tc_button'] = plugins_url( '/text-button.js', __FILE__ ); // CHANGE THE BUTTON SCRIPT HERE
            return $plugin_array;
        }

        function gavickpro_register_my_tc_button($buttons) {
           array_push($buttons, "gavickpro_tc_button");
           return $buttons;
        }

2. Then I created a file called text-button.js in the same theme folder as functions.php and added the code

            (function() {
                tinymce.PluginManager.add('gavickpro_tc_button',   function( editor, url ) {
                    editor.addButton( 'gavickpro_tc_button', {
                        text: 'My test button',
                        icon: false,
                        onclick: function() {
                            editor.insertContent('Hello World!');
                        }
                    });
                });
            })();

but this doesn't work, it makes all tinymce buttons in the editor disappear

screenshot of tinymce editor

Ultimately, just a little change (as suggested by Kaloyan Ivanov):

Change the line:

$plugin_array['gavickpro_tc_button'] = plugins_url( '/text-button.js', __FILE__ );

and:

$plugin_array['gavickpro_tc_button'] = get_bloginfo( 'stylesheet_directory' ) . '/text-button.js';

Thanks to Kaloyan Ivanov and gavick.com/blog, it's new tinymce editor for wordpress 4.1

Kaloyan

Check out the tutorial below, it appears to be the latest version of TinyMCE (and has been updated recently).

https://www.gavick.com/blog/wordpress-tinymce-custom-buttons

The tutorial you linked probably worked for TinyMCE in WordPress prior to 3.9.

Edit: Did a quick test. seems to be working. :)


Quick guide to get it working:

  1. Open https://www.gavick.com/blog/wordpress-tinymce-custom-buttons#tmce-section-1
  2. Paste the four codes of php into your functions.php file
  3. Replace plugins_url( '/text-button.js', __FILE__ );with get_bloginfo('stylesheet_directory') . /text-button.js(may need to be adjusted if the file is in a subdirectory).
  4. Paste the javascript code from the fifth paragraph into the javascript file you created.

(Note that this is just a quick example of implementing it in a theme , so you can see the main idea, if you're actually building a plugin, you should use the syntax).plugins_url( '/text-button.js', __FILE__ )

http://codex.wordpress.org/Function_Reference/plugins_url

Related


Wordpress 4.1 TinyMce Button Plugin

Rexspi I'm trying to add a button on tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled the a

Wordpress 4.1 TinyMce Button Plugin

Rexspi I am trying to add a button to the tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled

Wordpress 4.1 TinyMce Button Plugin

Rexspi I'm trying to add a button on tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled the a

Wordpress 4.1 TinyMce Button Plugin

Rexspi I am trying to add a button to the tinymce editor in wordpress WordPress version: 4.1 I followed this tutorial : http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182 But it doesn't work. I've at least googled

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

WordPress plugin tinymce conflict

tom I am using Wordpress and have installed two plugins on it. Both use the Tinymce WYSIWYG editor. If I activate both plugins at the same time, I get the following error message when the page plugin B is displayed: jquery.js? ver=1.12.3:2 Uncaught Error: Auto

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish and r

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a

TinyMCE WordPress Plugin Clickable Image

Sam Kogan| I'm trying to create a simple WordPress plugin for the TinyMCE editor, add a button in the editor bar, when you click the button, it will insert an image in the content, and I want the image to be available to read the image's People click publish a