Bước 1 :
Cài plugin : TinyMCE Advanced
Tạo folder trong đường dẫn vào plugin : /ibegins.net/public_html/wp-content/plugins
Đặt tên cho folder đó ví dụ : button-php
Bước 2 :
Tạo tiếp một file trong folder trên sẽ thành : /ibegins.net/public_html/wp-content/plugins/button-php/
Đặt tên dưới dạng file : button-php.php : /ibegins.net/public_html/wp-content/plugins/button-php/button-php.php
Gắn code sau vào file button-php.php :
/* Plugin Name: Visual Editor Buttons PHP Plugin URI: http://ibegins.net/ Description: Adds a button to visual editor[php_][/_php]. Author: Văn Tưởng */ // init process for registering our button add_action('init', 'ibegins_shortcode_button_init'); function ibegins_shortcode_button_init() { //Abort early if the user will never see TinyMCE if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') && get_user_option('rich_editing') == 'true') return; //Add a callback to regiser our tinymce plugin add_filter("mce_external_plugins", "ibegins_register_tinymce_plugin"); // Add a callback to add our button to the TinyMCE toolbar add_filter('mce_buttons', 'ibegins_add_tinymce_button'); } //This callback registers our plug-in function ibegins_register_tinymce_plugin($plugin_array) { $plugin_array['ibegins_button'] = plugin_dir_url( __FILE__ ) . 'button-js.js'; return $plugin_array; } //This callback adds our button to the toolbar function ibegins_add_tinymce_button($buttons) { //Add the button ID to the $button array $buttons[] = "ibegins_button"; return $buttons; }
Bước 3 :
Tạo tiếp một file JS trong folder button-php : /ibegins.net/public_html/wp-content/plugins/button-php/
Đặt tên file JS đó button-js.js : /ibegins.net/public_html/wp-content/plugins/button-php/button-js.js
Gắn code sau vào file button-js.js :
jQuery(document).ready(function($) { tinymce.create('tinymce.plugins.ibegins_plugin', { init : function(ed, url) { // Register command for when button is clicked ed.addCommand('ibegins_insert_shortcode', function() { selected = tinyMCE.activeEditor.selection.getContent(); if( selected ){ //If text is selected when button is clicked //Wrap shortcode around it. content = ' [php_]'+selected+'[/_php] '; }else{ content = ' [php_]'; } tinymce.execCommand('mceInsertContent', false, content); }); // Register buttons - trigger above command when clicked ed.addButton('ibegins_button', {title : 'Insert [php]
‘, cmd : ‘ibegins_insert_shortcode’, image: url + ‘/HTML5.png’ });
},
});
// Register our TinyMCE plugin
// first parameter is the button ID1
// second parameter must match the first parameter of the tinymce.create() function above
tinymce.PluginManager.add(‘ibegins_button’, tinymce.plugins.ibegins_plugin);
});
[/php]
Bước 4 :
Tải file ảnh và thay đường link ảnh trong button-js.js trong folder button-php
Bước 5 :
Vào quản lý admin website và kích hoạt plugin đó lên.
Chú ý : bỏ dấu gạch _ ở chữ php.
Chúc bạn thành công.
Tagged with: button editor php, button php, code đóng thẻ php
Dưới là đoạn code thay đổi chữ Add to cart và thêm giỏ hàng của woo năm 2023, phiên bản mới nhất cho wordpress...
Bạn có biết bạn có thể hiển thị nhiều đồng hồ trong Windows 11/10 không? Bạn có thể để Windows 11/10/8/7 hiển thị...
Bảng tổng hợp thật tuyệt vời! Chúng là một trong những tính năng mạnh mẽ nhất của Excel , chúng cho phép bạn nhanh...
Tìm cửa hàng bán Ghế sofa ở tại Hải Phòng, đơn vị cung cấp và sản xuất ghế sofa uy tín – chuyên nghiệp, nơi...
Thêm mục đăng bài trong danh mục sản phẩm " Add editor to Wordpress WooCommerce Product Category Page ", nhiều người đang cần...
Hướng dẫn việc tích hợp kết nối API lấy dữ liệu từ Contact Form 7 tới Google Sheet là một vấn đề đang được...
Bình luận bài viết
Đăng nhập để bình luận và xem các bình luận khác.