learndash_pdf_author
Filters the name of the pdf author. Filters the PDF author name when generating a certificate, allowing customization of the displayed author.
add_filter( 'learndash_pdf_author', $callback, 10, 1 );
Description
This filter allows developers to modify the PDF author's name before it's applied to a certificate generated by LearnDash. You can change the author string, access the TCPDF object, and use the certificate ID for dynamic adjustments. This hook fires during the PDF generation process for certificates.
Usage
add_filter( 'learndash_pdf_author', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example function to modify the PDF author name for LearnDash certificates.
*
* This function appends the site's name to the default author name,
* making it clear which website issued the certificate.
*
* @param string $pdf_author_name The original PDF author name.
* @param TCPDF $pdf The TCPDF object instance.
* @param int $cert_id The ID of the certificate post.
* @return string The modified PDF author name.
*/
function my_custom_learndash_pdf_author( $pdf_author_name, $pdf, $cert_id ) {
// Get the site's name to append to the author.
$site_name = get_bloginfo( 'name' );
// Ensure we have a site name before appending.
if ( ! empty( $site_name ) ) {
$pdf_author_name .= ' - ' . esc_html( $site_name );
}
// You could also conditionally change the author based on the certificate ID.
// For example, if $cert_id === 123, you might set a specific author.
// if ( $cert_id === 123 ) {
// $pdf_author_name = 'Specific Instructor Name';
// }
return $pdf_author_name;
}
// Add the filter to WordPress. The '10' is the default priority, and '3'
// indicates that our function accepts three arguments ($pdf_author_name, $pdf, $cert_id).
add_filter( 'learndash_pdf_author', 'my_custom_learndash_pdf_author', 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/includes/tcpdf-certificate-code.php:562
/**
* Filters the name of the pdf author.
*
* @param string $pdf_author_name PDF author name.
* @param TCPDF $pdf `TCPDF` class instance.
* @param int $cert_id Certificate post ID.
*/
$pdf->SetAuthor( apply_filters( 'learndash_pdf_author', $cert_args['pdf_author_name'], $pdf, $cert_args['cert_id'] ) );
/**
* 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.