learndash_certification_content_write_cell_before
Fires before the certificate content is added to the PDF. Fires before LearnDash certificate content is written to the PDF, allowing modification of the TCPDF object and arguments.
add_action( 'learndash_certification_content_write_cell_before', $callback, 10, 1 );
Description
Fires just before LearnDash adds specific content to a certificate PDF. This action hook allows developers to intervene and modify the TCPDF instance or certificate arguments before content is written, offering fine-grained control over certificate generation.
Usage
add_action( 'learndash_certification_content_write_cell_before', 'your_function_name', 10, 1 );
Examples
add_action( 'learndash_certification_content_write_cell_before', 'my_learndash_add_custom_text_to_certificate', 10, 2 );
/**
* Adds custom text to the bottom of a LearnDash certificate before the main content is written.
*
* @param TCPDF $pdf The TCPDF object instance.
* @param array $cert_args An array of arguments related to the certificate.
*/
function my_learndash_add_custom_text_to_certificate( TCPDF $pdf, array $cert_args ) {
// Get the current page width for positioning.
$page_width = $pdf->getPageWidth();
// Define custom text and its styling.
$custom_text = 'This certificate is awarded by My Awesome Academy.';
$font_size = 8;
$text_color = array( 100, 100, 100 ); // Dark grey
$y_position = $pdf->getPageHeight() - 30; // Position 30 units from the bottom.
// Set font for the custom text.
$pdf->SetFont( 'helvetica', '', $font_size );
$pdf->SetTextColor( ...$text_color );
// Add the custom text to the PDF, centered horizontally.
$pdf->SetXY( 0, $y_position ); // Reset X to 0 for centering calculation
$pdf->Cell( 0, 10, $custom_text, 0, 0, 'C' ); // Width 0 means full width, 'C' centers text.
// Reset text color and font for subsequent content.
$pdf->SetTextColor( 0, 0, 0 ); // Black
$pdf->SetFont( 'helvetica', '', 12 ); // Default font size
}
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:744
* Fires before the certificate content is added to the PDF.
*
* @param TCPDF $pdf `TCPDF` class instance.
* @param array $cert_args Array of certificate args.
*
* @since 3.3.0
*/
do_action( 'learndash_certification_content_write_cell_before', $pdf, $cert_args );
$pdf_cell_args = array(
'w' => 0,
'h' => 0,
'x' => '',
'y' => '',
'content' => $cert_content,