Filter uncanny-automator-pro

learndash_certificate_styles

Filters the arguments used to generate a LearnDash certificate's styles, allowing for customization.

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

Description

Filter this hook to control whether certificate CSS styles are included in the certificate content. By default, styles are included. Developers can return `false` to prevent style injection or modify the styles themselves. This hook fires before certificate styles are applied.


Usage

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

Parameters

$cert_args (mixed)
This parameter determines whether to include certificate CSS styles in the certificate content.

Return Value

The filtered value.


Examples

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

/**
 * Example of how to add custom CSS to LearnDash certificates.
 *
 * This function intercepts the learndash_certificate_styles filter and allows
 * you to inject custom CSS directly into the certificate output.
 *
 * @param bool $include_certificate_styles Whether to include the default certificate styles.
 * @param int  $cert_id The ID of the certificate post.
 * @return string The CSS styles to be applied to the certificate.
 */
function my_learndash_custom_certificate_styles( $include_certificate_styles, $cert_id ) {
    // If the filter is explicitly set to false, we won't add any styles.
    if ( ! $include_certificate_styles ) {
        return '';
    }

    // You can conditionally add styles based on the certificate ID,
    // for example, if you have different styling needs for different certificates.
    if ( 123 === $cert_id ) { // Replace 123 with an actual certificate ID you want to style
        $custom_styles = "
            <style type='text/css'>
                .certificate-wrapper {
                    border: 5px dashed #0073aa;
                    background-color: #f0f8ff;
                }
                .certificate-title {
                    color: #d9534f;
                    font-family: 'Georgia', serif;
                }
            </style>
        ";
        return $custom_styles;
    }

    // You could also retrieve styles from theme options or custom settings.
    // For demonstration, let's add a simple conditional style.
    $site_branding_color = get_theme_mod( 'header_textcolor' ); // Example: get a theme option
    if ( ! empty( $site_branding_color ) ) {
        $conditional_styles = "
            <style type='text/css'>
                .certificate-footer {
                    color: #" . esc_attr( $site_branding_color ) . ";
                    font-weight: bold;
                }
            </style>
        ";
        return $conditional_styles;
    }

    // If no specific conditions are met or no custom styles are defined,
    // return an empty string to rely on LearnDash's default styling or
    // whatever other filters might be applied.
    return '';
}

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

uncanny-automator-pro/src/integrations/learndash/helpers/learndash-pro-helpers.php:879

/**
		 * 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.
		 */
		$certificate_styles = '';
		if ( apply_filters( 'learndash_certificate_styles', true, $cert_args['cert_id'] ) ) {
			$setting_styles = LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Certificates_Styles', 'styles' );
			$setting_styles = preg_replace( '/<style[^>]*?>(.*?)</style>/is', '$1', $certificate_styles );
			if ( ! empty( $setting_styles ) ) {
				$certificate_styles = $setting_styles;
			}
		}


Scroll to Top