• Resolved marekbo12

    (@marekbo12)


    Hello.
    I would like to replace default formats styles with my custom styles. I add code to functions.php and I see this class names in dropdown format, but when I chose them, nothing happend – tags are not replaced. I don’t what is wrong. I check ‘create css classes menu’, I remove cached…thank you.
    My code:

    /* personalizacja TinyMCE WYSIWYG */
    function wpb_mce_buttons_2($buttons) {
        array_unshift($buttons, 'styleselect');
        return $buttons;
    }
    add_filter('mce_buttons_2', 'wpb_mce_buttons_2');
    
    /*
    * Callback function to filter the MCE settings
    */
    function my_mce_before_init_insert_formats( $init_array ) {  
     
    // Define the style_formats array
     
        $style_formats = array(  
    /*
    * Each array child is a format with it's own settings
    * Notice that each array has title, block, classes, and wrapper arguments
    * Title is the label which will be visible in Formats menu
    * Block defines whether it is a span, div, selector, or inline style
    * Classes allows you to define CSS classes
    * Wrapper whether or not to add a new block-level element around any selected elements
    */
            array(  
                'title' => 'Podtytu? do sekcji H4', 
                'block' => 'h4',  
                'classes' => 'podtytul-sekcji-h4',
                'wrapper' => true,
            ),  
            array(  
                'title' => '?ródtytu? do sekcji H5',  
                'block' => 'h5', 
                'classes' => 'srodtytul-sekcji-h5',
                'wrapper' => true,
            ),
            array(  
                'title' => 'Tytu? zdj?cia',  
                'block' => 'h6',
                'classes' => 'tytul-zdjecia',
                'wrapper' => true,
            ),
            array(  
                'title' => 'Tytu? tabelki',  
                'block' => 'h6',  
                'classes' => 'tytul-tabelki',
                'wrapper' => true,
            ),
            array(  
                'title' => '?ród?o',  
                'block' => 'h6',  
                'classes' => 'zrodlo',
                'wrapper' => true,
            ),
            array(  
                'title' => 'Tekst wyró?niony',  
                'block' => 'blockqoute',
                'classes' => 'tekst-wyrozniony',
                'wrapper' => true,
            ),
        );  
        // Insert the array, JSON ENCODED, into 'style_formats'
        $init_array['style_formats'] = json_encode( $style_formats );  
         
        return $init_array;  
       
    } 
    // Attach callback to 'tiny_mce_before_init' 
    add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' );
    
    // Add custom_editor_style to theme
    function my_theme_add_editor_styles() {
        add_editor_style( 'css/custom-editor-style.css' );
    }
    add_action( 'init', 'my_theme_add_editor_styles' ); 
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Andrew Ozz

    (@azaozz)

    I’ve seen few reports that custom styles stopped working, but unfortunately wasn’t able to reproduce. Does it still happen after the latest update? Any chance -something- is reverting the changes you add to the init array?

    Thread Starter marekbo12

    (@marekbo12)

    my array looks like this right now:

    `$style_formats = array(
    array(
    ‘title’ => ‘Podtytu? do sekcji H4’,
    ‘format’ => ‘h4’,
    ),
    array(
    ‘title’ => ‘?ródtytu? do sekcji H5’,
    ‘format’ => ‘h5’,
    ),
    array(
    ‘title’ => ‘Tytu? zdj?cia i tabelki’,
    ‘format’ => ‘h6’,
    ),
    array(
    ‘title’ => ‘?ród?o’,
    ‘block’ => ‘h6’,
    ‘classes’ => ‘zrodlo’,
    ),
    array(
    ‘title’ => ‘Tekst wyró?niony’,
    ‘block’ => ‘p’,
    ‘classes’ => ‘tekst-wyrozniony’,
    ‘wrapper’ => false,
    ),
    array(
    ‘title’ => ‘Zwyk?y paragraf’,
    ‘format’ => ‘p’,
    ),
    );`
    I don’t know exactly why this works now, but probably because of better understanding how works ‘format’ and ‘block’.

    • This reply was modified 6 years, 3 months ago by marekbo12.
    • This reply was modified 6 years, 3 months ago by marekbo12.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Styles doesn’t work’ is closed to new replies.