• Resolved David Borrink

    (@davidborrink)


    Using this thread, I was able to add my own custom fonts to the font family menu.

    I added this to my functions.php file …

    function confit_child_register_tinymce_fonts( $settings ) {
            $settings['font_formats'] =
                'Arial=arial,helvetica,sans-serif;'.
                'Marker Felt=marker felt wide;'.   // Added our own @font-face font
                '';
            return $settings;
        }
        add_filter('tiny_mce_before_init', 'confit_child_register_tinymce_fonts');

    …and it brings up Arial and Marker Felt in the menu, and my test post shows them working fine.

    But in the pulldown menu in the editor “Arial” is displayed in Arial, but “Marker Felt” is displayed in Times. What do I need to do to get my custom font displayed properly in the menu, and will this also help my font display properly in the editing window? It also shows up in Times.

    https://wordpress.org/plugins/wp-edit/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Josh

    (@josh401)

    Hi David,

    Okay, to get the font to display properly throughout, there are three places where the font style must be defined:

    1) The content editor css.
    2) The admin panel css.
    3) The front-end css.

    These correspond (respectively) to the following:

    1) For rending the font inside the content editor.
    2) For rendering the font inside the dropdown list.
    3) For rendering the font on the front-end pages.

    The purpose of the code snippet above (in your post) is to set the font names and font style to apply to each name; in the font dropdown selector; and apply that name to the selected content inside the editor. That’s it.

    To get the style to render properly, the css declaration must be made in the three areas I mentioned above. It sounds like you have #3 already covered. So, you need to add the css for numbers one and two.

    For number one; you need to add the css rule for your font to the content editor css. There are a number of ways to do this, but I’ll show one example implementation.

    @font-face {
        font-family: 'marker felt wide';
        src: url(PATH_TO_THE_FONT.woff);
    }

    This needs to be saved as a stylesheet; and then applied to the content editor initialization values. Here is one way to do so:

    function my_new_editor_fonts($init) {
    
        // Define new stylesheet location
        $new_css = "PATH_TO_THE_STYLESHEET.css";
    
        // If current stylesheets exist; we need to add ours to exisitng
        if(isset($init['content_css')) {
    
            $old_css = $init['content_css'];
            $init['content_css'] = $old_css . ', ' . $new_css;
        }
        // Else no current stylesheets; set ours as new
        else {
    
            $init['content_css'] = $new_css;
        }
    
        return $init;
    }
    add_filter( 'tiny_mce_before_init', 'my_new_editor_fonts' );

    This applies the custom css (which contains the font declaration) to the content editor; which will make the font render properly in the content editor.

    For number two; it’s a bit easier. You just need to create another stylesheet, with the same font declaration, and add it to the WordPress admin panel css.

    The stylesheet will be the same as the one used in the first part of number one (above). The function to add the css is a bit different. One way is to add the css to all admin pages:

    function load_custom_wp_admin_css() {
            wp_register_style( 'my_custom_wp_admin_css', 'PATH_TO_THE_STYLESHEET.css', false, '1.0.0' );
            wp_enqueue_style( 'my_custom_wp_admin_css' );
    }
    add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_css' );

    This will load the custom css file into all admin pages. Doing so will make the font render properly in the font selector dropdown list.

    Remember, the paths to your stylesheets need to be set properly. You may need to use different WordPress functions for the location to your css, depending on where you save the file.

    Lastly, the Pro version REALLY simplifies this entire process.

    Let me know if you get stuck along the way.

    Plugin Author Josh

    (@josh401)

    Okay; I’m going to mark this as resolved.

    Let me know if you still would like some assistance.

    Thread Starter David Borrink

    (@davidborrink)

    I’ve yet to try it due to other things my client wants first, but if I have a question.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Want custom font in Visual Editor to use the font chosen’ is closed to new replies.