yanknudtskov
4/18/2017 - 12:58 PM

WordPress Changing Editor Styles

WordPress Changing Editor Styles

<?php

class vgr_add_editor_styles {

	public function __construct() {

		add_filter('tiny_mce_before_init', array($this, 'change_editor'), 10, 2);
		add_filter( 'mce_buttons', array($this, 'fb_mce_editor_buttons') );

		add_action( 'admin_init', array($this, 'add_editor_styles') );

	}

	function fb_mce_editor_buttons( $buttons ) {

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

	public function add_editor_styles() {
		add_editor_style( 'https://fonts.googleapis.com/css?family=Lato:100,300,regular,700,900' );
		add_editor_style( get_stylesheet_directory_uri() . '/assets/fonts/pioneerbrush-webfont/stylesheet.css' );
		add_editor_style( get_stylesheet_directory_uri().'/editor_styles.css' );
	}

	public function change_editor( $mceInit, $editor_id ) {

		$style_formats = array(

			array(
				'title' => 'Heading 1',
				'block' => 'h1',
				'exact' => true
			),
			array(
				'title' => 'Heading 2',
				'block' => 'h2',
				'exact' => true
			),
			array(
				'title' => 'H2 Manchet',
				'block' => 'h2',
				'attributes' => array(
					'class' => 'manchet'
				),
				'exact' => true
			),
			array(
				'title' => 'Heading 3',
				'block' => 'h3',
				'exact' => true
			),
			array(
				'title' => 'H3 Teaser capital',
				'block' => 'h3',
				'attributes' => array(
					'class' => 'teaser capital'
				),
				'exact' => true
			),
			array(
				'title' => 'H3 Teasear article',
				'block' => 'h3',
				'attributes' => array(
					'class' => 'teaser article'
				),
				'exact' => true
			),
			array(
				'title' => 'Heading 4',
				'block' => 'h4',
				'exact' => true
			),
			array(
				'title' => 'Paragraph teaser',
				'block' => 'p',
				'attributes' => array(
					'class' => 'teaser'
				),
				'exact' => true
	),
				array(
					'title' => 'Paragraph',
					'block' => 'p',
					'exact' => true
			),
		);

		$mceInit['style_formats'] = json_encode( $style_formats );
//		$mceInit['style_formats_merge'] = true;

		return $mceInit;
	}

}

new vgr_add_editor_styles();