Advertisement
Milonsinha

Despret-5

Aug 1st, 2017
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. SHORDCODE TUTORIAL
  2. =============================
  3. javascript website http://www.wpexplorer.com/wordpress-tinymce-tweaks/
  4.  
  5. functions.php
  6. ======================
  7. function features_shortcode($atts){
  8. extract(shortcode_atts(array(
  9. 'icon' => '',
  10. 'title' => '',
  11. 'text' => '',
  12. ), $atts));
  13. return '
  14. <div class="feature-wrap">
  15. <i class="fa fa-'.$icon.'"></i>
  16. <h2>'.$title.'</h2>
  17. <h3>'.$text.'</h3>
  18. </div>
  19. ';
  20.  
  21.  
  22.  
  23. }
  24. add_shortcode('features','features_shortcode');
  25.  
  26. //video shortcode
  27.  
  28. function youtube_shortcode($atts){
  29. extract(shortcode_atts(array(
  30. 'id' => '',
  31. ), $atts));
  32. return '<div class="embed-responsive embed-responsive-16by9">
  33. <iframe width="640" class="embed-responsive-item" height="360" src="//www.youtube.com/embed/'.$id.'" frameborder="0" allowfullscreen></iframe>
  34. </div>
  35. ';
  36.  
  37.  
  38.  
  39. }
  40. add_shortcode('youtube','youtube_shortcode');
  41.  
  42.  
  43.  
  44. // Shortcode button 1
  45. function corlate_theme_tinymce_btn() {
  46. // check user permissions
  47. if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
  48. return;
  49. }
  50. // check if WYSIWYG is enabled
  51. if ( 'true' == get_user_option( 'rich_editing' ) ) {
  52. add_filter( 'mce_external_plugins', 'corlate_theme_tinymce_plugin' );
  53. add_filter( 'mce_buttons', 'corlate_theme_tinymce_button' );
  54. }
  55. }
  56. add_action('admin_head', 'corlate_theme_tinymce_btn');
  57.  
  58. // Declare script for new button
  59. function corlate_theme_tinymce_plugin( $plugin_array ) {
  60. $plugin_array['corlate_buttons'] = get_template_directory_uri() .'/js/shortcode-buttons.js';
  61. return $plugin_array;
  62. }
  63.  
  64. // Register new button in the editor
  65. function corlate_theme_tinymce_button( $buttons ) {
  66. array_push( $buttons, 'corlate_buttons' );
  67. return $buttons;
  68. }
  69.  
  70.  
  71. shortcode-button.js
  72. =================================
  73. // Shortcode buttons2
  74. (function() {
  75. tinymce.PluginManager.add('corlate_buttons', function( editor, url ) {
  76. editor.addButton('corlate_buttons', {
  77. text: 'Youtube Video',
  78. icon: false,
  79. onclick: function() {
  80. editor.windowManager.open( {
  81. title: 'Insert Random Shortcode',
  82. body: [
  83. {
  84. type: 'textbox',
  85. name: 'textboxName',
  86. label: 'Text Box',
  87. value: '30'
  88. },
  89. {
  90. type: 'textbox',
  91. name: 'multilineName',
  92. label: 'Multiline Text Box',
  93. value: 'You can say a lot of stuff in here',
  94. multiline: true,
  95. minWidth: 300,
  96. minHeight: 100
  97. },
  98. {
  99. type: 'listbox',
  100. name: 'listboxName',
  101. label: 'List Box',
  102. 'values': [
  103. {text: 'Option 1', value: '1'},
  104. {text: 'Option 2', value: '2'},
  105. {text: 'Option 3', value: '3'}
  106. ]
  107. }
  108. ],
  109. onsubmit: function( e ) {
  110. editor.insertContent( '[random_shortcode textbox="' + e.data.textboxName + '" multiline="' + e.data.multilineName + '" listbox="' + e.data.listboxName + '"]');
  111. }
  112. });
  113.  
  114. }
  115.  
  116. });
  117.  
  118.  
  119.  
  120. });
  121. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement