Filter uncanny-continuing-education-credits

learndash_certificate_styles

Filters whether to include certificate CSS styles in certificate content or not. Filters whether to include certificate CSS styles in the certificate content, controlled by certificate ID.

add_filter( 'learndash_certificate_styles', $callback, 10, 2 );

Description

This filter allows developers to control whether certificate CSS styles are included in the certificate output. Developers can return `false` to prevent styles from being embedded, useful for custom styling or conditional rendering. The certificate ID is provided for context.


Usage

add_filter( 'learndash_certificate_styles', 'your_function_name', 10, 2 );

Parameters

$include_certificate_styles (boolean)
Whether to include certificate styles.
$cert_id (int)
Certificate post ID.

Return Value

The filtered value.


Examples

<?php
/**
 * Example function to conditionally disable certificate styles based on certificate ID.
 *
 * This function demonstrates how to use the 'learndash_certificate_styles' filter
 * to prevent certificate styles from being included for specific certificates.
 * In this example, we'll disable styles for certificates with an ID of 123.
 *
 * @param boolean $include_certificate_styles Whether to include certificate styles.
 * @param int     $cert_id                    Certificate post ID.
 * @return boolean                             The modified value of $include_certificate_styles.
 */
function my_custom_learndash_certificate_styles( $include_certificate_styles, $cert_id ) {
    // Check if the current certificate ID is one we want to exclude styles from.
    if ( $cert_id === 123 ) {
        // If it is, return false to prevent the styles from being included.
        return false;
    }

    // For all other certificates, keep the default behavior.
    return $include_certificate_styles;
}

// Add the filter to WordPress.
// The '3' indicates that our callback function accepts three arguments:
// $include_certificate_styles, $cert_id, and any other arguments the hook might pass.
// We only care about the first two, but it's good practice to account for them if they exist.
add_filter( 'learndash_certificate_styles', 'my_custom_learndash_certificate_styles', 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:454

/**
		 * Filters whether to include certificate CSS styles in certificate content or not.
		 *
		 * @param boolean $include_certificate_styles Whether to include certificate styles.
		 * @param int $cert_id Certificate post ID.
		 */
		if ( apply_filters( 'learndash_certificate_styles', true, $cert_args['cert_id'] ) ) {
			$certificate_styles = LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Certificates_Styles', 'styles' );
			$certificate_styles = preg_replace( '/<style[^>]*?>(.*?)</style>/is', '$1', $certificate_styles );
			if ( ! empty( $certificate_styles ) ) {
				$cert_content = '<style>' . $certificate_styles . '</style>' . $cert_content;
			}
		}


Scroll to Top