uo_learndash_certificate_font
Filters the font used for LearnDash certificates before it's applied.
add_filter( 'uo_learndash_certificate_font', $callback, 10, 2 );
Description
Allows developers to modify the font used for LearnDash certificates. This filter can be used to dynamically set a custom font or override the default font based on certificate arguments or other logic. The hook provides the current font value and certificate arguments for manipulation.
Usage
add_filter( 'uo_learndash_certificate_font', 'your_function_name', 10, 2 );
Parameters
-
$font(mixed) - This parameter holds the font name to be used for the certificate, which can be filtered or set directly.
-
$cert_args(mixed) - This parameter contains the font name or path to be used for the certificate.
Return Value
The filtered value.
Examples
/**
* Example of how to use the uo_learndash_certificate_font filter to change the default font for a LearnDash certificate.
*
* This example checks if a custom font is specified via a URL parameter. If not,
* it falls back to a predefined default font. It also demonstrates how to
* conditionally apply a different font based on the certificate ID.
*
* @param string $font The current font name.
* @param int $cert_id The ID of the certificate being generated.
* @return string The font name to be used for the certificate.
*/
add_filter( 'uo_learndash_certificate_font', function( $font, $cert_id ) {
// Check if a custom font is passed via URL parameter
if ( ! empty( $_GET['custom_certificate_font'] ) ) {
$font = sanitize_text_field( $_GET['custom_certificate_font'] );
} else {
// Fallback to a default font if no custom font is provided via URL
$font = 'Arial'; // Default font
}
// Conditionally apply a different font for a specific certificate ID
if ( $cert_id === 123 ) { // Replace 123 with the actual certificate ID
$font = 'Times New Roman';
}
// Ensure we always return a font value
return $font;
}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/includes/tcpdf-certificate-code.php:352
}
$cert_args['pdf_keywords'] = implode( ' ', $tags_array );
}
if ( ! empty( $_GET['font'] ) ) {
$font = esc_html( $_GET['font'] );
}
$font = apply_filters( 'uo_learndash_certificate_font', $font, $cert_args['cert_id'] );
if ( ! empty( $_GET['monospaced'] ) ) {
$monospaced_font = esc_html( $_GET['monospaced'] );
}
$monospaced_font = apply_filters( 'uo_learndash_certificate_monospaced_font', $monospaced_font, $cert_args['cert_id'] );
if ( ! empty( $_GET['fontsize'] ) ) {