Browse: Home / Snippets /

Upload custom font into TCPDF

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

1. Create a new folder in our common LearnDash directory: 'wp-content/uploads/learndash/tcpdf/fonts/'

2. Next, using FTP or similar, copy all the fonts from includes/lib/tcpdf/fonts/ and copy them to wp-content/uploads/learndash/tcpdf/fonts/

3. Add the below code snippet to your child theme's functions.php file:

add_action( 'learndash_init', function() {
    if ( ! defined( 'K_PATH_FONTS' ) ) {
        $wp_upload_dir = wp_upload_dir();
        $basedir = str_replace( '\\', '/', $wp_upload_dir['basedir'] );
        $ld_tcpdf_fonts_dir = trailingslashit( $basedir ) . 'learndash/tcpdf/fonts/';
        define( 'K_PATH_FONTS', $ld_tcpdf_fonts_dir );
    }
});

4. Now you can go about adding custom fonts as you like into this folder and no worries about the next time updating LearnDash.

As a final note due to how the TCPDF config file is coded

wp-content/plugins/sfwd-lms/includes/vendor/tcpdf/config/tcpdf_config.php

You may see a PHP Notice about K_PATH_FONTS already defined. This is because in the tcpdf_config.php file it does not first check if 'K_PATH_FONTS' is possibly already defined