Filter uncanny-automator-pro

learndash_pdf_title

Filters the title of the pdf. Filters the title of a LearnDash PDF, allowing modification before it's generated and displayed.

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

Description

Filters the PDF document title before it's generated. This hook allows developers to dynamically modify the PDF title, providing custom naming conventions or including specific certificate details. It fires during PDF generation, before the title is set on the TCPDF instance.


Usage

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

Return Value

The filtered value.


Examples

// Add a prefix to the PDF title for all LearnDash certificates.
add_filter( 'learndash_pdf_title', 'my_prefix_learndash_certificate_title', 10, 3 );

function my_prefix_learndash_certificate_title( $pdf_title, $pdf, $cert_id ) {
    // Check if the certificate ID is valid and if the title is not empty.
    if ( $cert_id > 0 && ! empty( $pdf_title ) ) {
        // Get the post object for the certificate to potentially access other data if needed.
        $certificate_post = get_post( $cert_id );

        // You could add more complex logic here, for example:
        // - Check the course the certificate is associated with.
        // - Check the user who earned the certificate.
        // - Dynamically generate a title based on user or course data.

        // For this example, we'll simply prepend "Official: " to the existing title.
        return 'Official: ' . $pdf_title;
    }

    // Return the original title if no modification is needed.
    return $pdf_title;
}

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:1008

/**
		 * Filters the title of the pdf.
		 *
		 * @param string $pdf_title PDF title.
		 * @param TCPDF $pdf `TCPDF` class instance.
		 * @param int $cert_id Certificate post ID.
		 */
		$pdf->SetTitle( apply_filters( 'learndash_pdf_title', $cert_args['pdf_title'], $pdf, $cert_args['cert_id'] ) );

		/**
		 * Filters the subject of the pdf.
		 *
		 * @param string $pdf_subject PDF subject
		 * @param TCPDF $pdf `TCPDF` class instance.
		 * @param int $cert_id Certificate post ID.


Scroll to Top