• Resolved mengeco

    (@mengeco)


    Hello

    As I did on my other themes, I want to add custom styles accessible from the WordPress toolbar (see https://snag.gy/6Z5amj.jpg).

    This allows you to add a “Format” button to scroll through all custom styles.

    I add my code in “functions.php”, I create my styles normally in style.css and it’s ok.

    But I tried with Ocean WP and it does not work. My code in function.php:

    /* STYLES PERSONNALISES ================================================== */
    function wpb_mce_buttons_2($buttons) {
    array_unshift($buttons, ‘styleselect’);
    return $buttons;
    }
    add_filter(‘mce_buttons_2’, ‘wpb_mce_buttons_2’);

    /* STYLES PERSONNALISES : affichage des styles dans l’admin WP ================================================== */

    add_action( ‘admin_init’, ‘my_theme_add_admin_styles’ );/*Nom de ma fonction : libre*/
    function my_theme_add_admin_styles() { /*Appel de ma fonction*/
    add_editor_style( ‘style-custom.css’ ); /*chemin et nom de ma feuille de style*/
    }

    /* STYLES PERSONNALISES : liste des styles ================================================== */

    function my_mce_before_init_insert_formats( $init_array ) {

    $style_formats = array(

    array(‘title’ =>
    ‘Bouton pdf (paragraphe)’,
    ‘block’ => ‘span’,
    ‘classes’ => ’bouton-pdf’,
    ‘wrapper’ => true,
    ),
    array(‘title’ =>
    ‘Encadré (paragraphe)’,
    ‘block’ => ‘span’,
    ‘classes’ => ‘encadre’,
    ‘wrapper’ => true,
    ),

    );
    // Insert the array, JSON ENCODED, into ‘style_formats’
    $init_array[‘style_formats’] = json_encode( $style_formats );

    return $init_array;

    }

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom styles from the WordPress toolbar’ is closed to new replies.