ld_certificate_link_label
Filters the text displayed for the "Print Your Certificate" button before it's shown to the user.
add_filter( 'ld_certificate_link_label', $callback, 10, 1 );
Description
This filter allows developers to customize the text label displayed for the course certificate link. It's applied before the certificate link is output, enabling dynamic label generation based on user or course data. Use this hook to modify the default "PRINT YOUR CERTIFICATE" to suit your needs.
Usage
add_filter( 'ld_certificate_link_label', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example function to modify the text of the certificate link label.
*
* This function demonstrates how to use the 'ld_certificate_link_label'
* filter hook to change the default text displayed on the certificate link.
*
* @param string $label The current label text for the certificate link.
* @param int $user_id The ID of the user.
* @param int $post_id The ID of the post (course).
* @return string The modified label text.
*/
function my_custom_certificate_link_label( $label, $user_id, $post_id ) {
// Check if the user has completed the course and is eligible for a certificate.
// This is a hypothetical check. In a real scenario, you'd use LearnDash functions
// like learndash_is_user_completing_course() or similar to determine eligibility.
$course_completed = true; // Replace with actual check
if ( $course_completed ) {
// You could also conditionally change the label based on user meta or course settings.
// For example, if the course has a specific certificate name set.
$certificate_name = get_post_meta( $post_id, 'my_custom_certificate_name', true );
if ( ! empty( $certificate_name ) ) {
return sprintf(
esc_html__( 'Download Your %s', 'my-text-domain' ),
esc_html( $certificate_name )
);
} else {
return esc_html__( 'Download Your Certificate', 'my-text-domain' );
}
}
// If the user is not eligible, you might want to return an empty string
// or a different message, or just the default if the hook is applied elsewhere.
// For this example, we'll return the original label if not eligible.
return $label;
}
add_filter( 'ld_certificate_link_label', 'my_custom_certificate_link_label', 10, 3 );
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/templates/single-course.php:55
src/templates/drip-topic-template_legacy.php:60
src/templates/drip-template_legacy.php:60
* See https://bitbucket.org/snippets/learndash/7oe9K for example use of this filter.
*/
echo apply_filters( 'ld_after_course_status_template_container', '', learndash_course_status_idx( $course_status ), $course_id, $user_id );
?>
<?php if ( ! empty( $course_certficate_link ) ) : ?>
<div id="learndash_course_certificate" class="learndash_course_certificate">
<a href='<?php echo esc_attr( $course_certficate_link ); ?>' class="btn-blue" target="_blank"><?php echo apply_filters( 'ld_certificate_link_label', esc_attr__( 'PRINT YOUR CERTIFICATE', 'learndash' ), $user_id, $post->ID ); ?></a>
</div>
<br/>
<?php endif; ?>
<?php endif; ?>
<div class="learndash_content"><?php echo $content; ?></div>