How to change fonts on Certificates

WP Courseware's certificate is currently customizable, however, to customize the fonts, you'll have to write a few filters and place them in your functions.php file. 

To start, you will need a font. If you find a TTF or OTF font you will need to convert it so that the TCPDF library can use it. There is a  TCPDF font converter online that can convert your fonts. It will generate the three files described below.

Each font consists of 3 files. For example the Alexbrush font would have the following 3 files:

  • alexbrush.ctg.z
  • alexbrush.php
  • alexbrush.z

Once you have the font files, you can place the font files anywhere on your web server. In this example the fonts will be placed in the /wp-content/wpcourseware_uploads/fonts/ folder.

There are 3 fonts filters that control various text strings on the certificate:

  •  wpcw_certificate_primary_font
  • wpcw_certificate_secondary_font
  • wpcw_certificate_footer_font

Each filter has a set of arguments that you will need to return. They are as follows:

  •  family - This is the font family. Using the example from above, this would be alexbrush
  •  file - This is the location of the font files. In the example above, this would be set to something like: WP_CONTENT_DIR . '/wpcourseware_uploads/fonts/alexbrush.php'
  •  style - The style is only applicable if the font supports it. For example, if the font supports bold text, you could set this to B.
  •  size - This is the font size.
  •  footer_size - This argument is only applicable to the primary font and will set the font size on the two lower text strings for date and name of the instructor. The two upper strings for student name and course name will be set by the size argument.

Primary font filter example:

add_filter( 'wpcw_certificate_primary_font', 'wpcw_certificate_override_primary_font' );

function wpcw_certificate_override_primary_font( $font_args ) {
	$new_font_args = array(
		'family'      => 'alexbrush',
		'file'        => WP_CONTENT_DIR . '/wpcourseware_uploads/fonts/alexbrush.php',
		'style'       => '',
		'size'        => 10,
		'footer_size' => 15,
	);

	return $new_font_args;
}

Secondary font filter example:

add_filter( 'wpcw_certificate_secondary_font', 'wpcw_certificate_override_secondary_font' );

function wpcw_certificate_override_secondary_font( $font_args ) {
	$new_font_args = array(
		'family' => 'alexbrush',
		'file'   => WP_CONTENT_DIR . '/wpcourseware_uploads/fonts/alexbrush.php',
		'style'  => 'B',
		'size'   => 16,
	);

	return $new_font_args;
}

Footer font filter example:

add_filter( 'wpcw_certificate_footer_font', 'wpcw_certificate_override_footer_font' );

function wpcw_certificate_override_footer_font( $font_args ) {
	$new_font_args = array(
		'family' => 'alexbrush',
		'file'   => WP_CONTENT_DIR . '/wpcourseware_uploads/fonts/alexbrush.php',
		'style'  => 'B',
		'size'   => 16,
	);

	return $new_font_args;
}

Still need help? Contact Us Contact Us