php WordPress TinyMCE定制

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WordPress TinyMCE定制相关的知识,希望对你有一定的参考价值。

// ------------------------------------------------
// Add Word Count Plugin to TinyMCE Instances
// ------------------------------------------------

// Download plugin from TinyMCE website

// Add wordcount plugin to TinyMCE for all instances.
// add_filter('mce_external_plugins', 'pd_register_tinymce_plugins');

function pd_register_tinymce_plugins() {
  $plugins = array('wordcount'); // Add any more plugins you want to load here
  $plugins_array = array();

  // Build the response - the key is the plugin name, value is the URL to the plugin JS
  foreach ($plugins as $plugin ) {
    $plugins_array[$plugin] = get_template_directory_uri() . '/js/tinymce/plugins/wordcount/plugin.min.js';
  }

  return $plugins_array;
}
// ------------------------------------------------
// Add TinyMCE style formats.
// ------------------------------------------------

add_filter( 'mce_buttons_2', 'understrap_tiny_mce_style_formats' );

function understrap_tiny_mce_style_formats( $styles ) {

    array_unshift( $styles, 'styleselect' );
    return $styles;
}

add_filter( 'tiny_mce_before_init', 'understrap_tiny_mce_before_init' );

function understrap_tiny_mce_before_init( $settings ) {

  $style_formats = array(
      array(
          'title' => 'Lead Paragraph',
          'selector' => 'p',
          'classes' => 'lead',
          'wrapper' => true
      ),
      array(
          'title' => 'Small',
          'inline' => 'small'
      ),
      array(
          'title' => 'Blockquote',
          'block' => 'blockquote',
          'classes' => 'blockquote',
          'wrapper' => true
      ),
      array(
          'title' => 'Cite',
          'inline' => 'cite'
      )
  );
  
  if ( isset( $settings['style_formats'] ) ) {
    $orig_style_formats = json_decode($settings['style_formats'], true);
    $style_formats = array_merge($orig_style_formats, $style_formats);
  }

  $settings['style_formats'] = json_encode( $style_formats );

  return $settings;
}
// ----------------------------------------------------
//  Customize available block formats (headings, etc)
// ----------------------------------------------------  

function wb_remove_h1_from_editor( $init ) {
  // Add block format elements you want to show in dropdown
  $init['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;';
  return $init;
}
add_filter( 'tiny_mce_before_init', 'wb_remove_h1_from_editor' );
// -----------------------------------------------------
//  Load editor stylesheet
// ----------------------------------------------------  

function wb_theme_add_editor_styles() {
  add_editor_style( 'css/custom-editor-style.css' );
  $editor_font = '//fonts.googleapis.com/css?family=Palanquin:300,400,500,600,700';
  add_editor_style( $editor_font );
}
// add_action( 'admin_init', 'wb_theme_add_editor_styles' );

以上是关于php WordPress TinyMCE定制的主要内容,如果未能解决你的问题,请参考以下文章

php WordPress:创建TinyMCE自定义按钮

php WordPress:创建TinyMCE自定义按钮

php WordPress:创建TinyMCE自定义按钮

php WordPress:创建TinyMCE自定义按钮

php wordpress tinyMCE强制粘贴为文本

PHP Wordpress:自定义TinyMCE按钮