Certificate Builder Hooks: Output Mode, File Name and mPDF Instance
The four hooks in the LearnDash Certificate Builder, with working snippets: force PDFs to download, rename the file, password-protect or watermark through the mPDF instance, and extend the allowed block list.

The LearnDash Certificate Builder (1.1.2) has a short public API: four filters. Three run at the moment a PDF is served and one controls which blocks the editor offers. Between them they cover the requests that come up most often, from "make it download instead of opening in the tab" to "stamp a watermark on previews" and "let me use the image block". This reference documents each hook with its arguments, verified against the add-on source, and gives a snippet for the common use of each.
Where the hooks run
When a builder certificate is requested, the add-on's PDF service builds the document and then, in serve(), applies the hooks in this order: learndash_certificate_builder_mpdf on the configured mPDF object before any HTML is written, then after the content is written, learndash_certificate_builder_pdf_name and learndash_certificate_builder_pdf_output_mode immediately before Output(). All three receive the certificate ID and the awarded course or quiz ID where relevant, and both IDs are zero for previews. The fourth filter, learndash_certificate_builder_allowed_blocks, runs in the admin when the editor loads. Our walk-through of how the builder renders blocks with mPDF shows the surrounding pipeline.
learndash_certificate_builder_pdf_output_mode
Arguments: the destination constant, the certificate ID, the course ID. The default is Destination::INLINE, which opens the PDF in the browser. The constants are mPDF's Output\Destination class values: INLINE, DOWNLOAD, FILE and STRING_RETURN, whose string values are I, D, F and S. The bundled mPDF is namespaced under LearnDash\Certificate_Builder\Mpdf, so returning the plain string avoids referencing a prefixed class.
<?php
/**
* Force Certificate Builder PDFs to download instead of opening inline.
*
* @param string $mode Output destination constant.
* @param int $cert_id Certificate ID, 0 for previews.
* @param int $post_id Awarded course or quiz ID, 0 for previews.
*
* @return string
*/
function wwc_certificate_download_mode( $mode, $cert_id, $post_id ) {
if ( 0 === $cert_id ) {
return $mode; // Keep previews inline for editors.
}
return 'D';
}
add_filter( 'learndash_certificate_builder_pdf_output_mode', 'wwc_certificate_download_mode', 10, 3 );
Keeping previews inline matters, because an editor previewing a design does not want a download every time. Returning F writes the PDF to the path given as the file name and sends nothing to the browser, which is useful for a cron job that archives certificates but will look broken to a learner; combine it with your own redirect or response if you use it on a live request.
learndash_certificate_builder_pdf_name
Arguments: the generated name, the certificate ID, the course ID. The default name is the user login, course title, certificate title and site name joined with spaces, sanitised with sanitize_file_name(), ending in .pdf; previews are named preview.pdf. The filter receives the finished string, so you can replace it entirely:
<?php
/**
* Name certificate files as Certificate-{course}-{Lastname}-{date}.pdf.
*/
function wwc_certificate_file_name( $name, $cert_id, $post_id ) {
if ( 0 === $cert_id ) {
return $name;
}
$user = wp_get_current_user();
$course = get_post( $post_id );
$parts = [
'Certificate',
$course ? $course->post_title : $post_id,
$user->last_name ? $user->last_name : $user->user_login,
wp_date( 'Y-m-d' ),
];
return sanitize_file_name( implode( '-', $parts ) ) . '.pdf';
}
add_filter( 'learndash_certificate_builder_pdf_name', 'wwc_certificate_file_name', 10, 3 );
The current user is the learner in the normal flow and an administrator when an admin opens a learner's certificate from a report, so include the course and date rather than relying on the name alone if files are archived. With the F output mode, return an absolute path inside a protected directory instead of a bare file name.
learndash_certificate_builder_mpdf
Argument: the configured mPDF instance, returned after your changes. This is the hook for anything mPDF itself supports. Three examples:
<?php
/**
* Set document metadata, add a watermark to previews, and restrict editing.
*/
function wwc_certificate_mpdf( $mpdf ) {
$mpdf->SetAuthor( get_bloginfo( 'name' ) );
$mpdf->SetCreator( get_bloginfo( 'name' ) );
if ( is_preview() ) {
$mpdf->SetWatermarkText( 'PREVIEW' );
$mpdf->showWatermarkText = true;
}
// Allow printing and copying, block editing. Empty user password keeps it openable.
$mpdf->SetProtection( [ 'print', 'copy' ], '', wp_salt( 'auth' ) );
return $mpdf;
}
add_filter( 'learndash_certificate_builder_mpdf', 'wwc_certificate_mpdf' );
Protection with an empty user password lets anyone open the file while preventing modification in most readers; a non-empty user password would require learners to type it, which is rarely wanted. The watermark call is a plain mPDF feature and applies to every page. You can also set the title here, although the title is better derived in the name filter since both have the course ID.
Because serve() applies this filter before writing the stylesheet and HTML, you cannot inspect the rendered content here, only configure the engine. Settings that must be in place before fonts load, such as additional font directories, should also be applied here; the add-on has already registered its bundled and uploaded fonts by this point, so a font added here needs its own fontdata entry and directory.
learndash_certificate_builder_allowed_blocks
Argument: the array of block names the editor offers for certificates. The default list is columns, paragraph, heading, spacer, shortcode, image, quote, list, separator, and the four LearnDash data blocks for course, user, group and quiz information. Adding a block to the list makes it insertable; it does not make it render correctly, because blocks without a dedicated renderer fall through to the fallback, which emits their raw HTML for mPDF to interpret as best it can.
<?php
add_filter(
'learndash_certificate_builder_allowed_blocks',
function ( $blocks ) {
$blocks[] = 'core/table';
return $blocks;
}
);
Simple HTML blocks such as tables tend to work through the fallback because mPDF handles table markup; interactive or script-driven blocks do not. Test every added block in a preview and in a real download before relying on it, and see the supported blocks guide for what each renderer does.
Hooks that do not exist
There is no filter on the generated HTML or CSS, no action after the PDF is produced, and no hook to change the file name for the classic engine from this add-on; classic certificates have their own filters such as learndash_pdf_filename and the learndash_certification_created action, covered in LearnDash certificate hooks. If you need to post-process a builder PDF, for example to store a copy, use the mPDF instance filter to set a file output path, or output as a string from your own code path by calling the service directly.
Testing hooks safely
Put the code in a site plugin, enable it on staging, and test three paths: a preview from the certificate editor, a learner's download from a completed course, and an administrator opening the same certificate from a report. The IDs the filters receive differ between them, and a callback that assumes a course ID will misbehave on previews. Check the browser's download name and open the file's document properties to confirm metadata and protection.
When to get help
These four hooks are enough for naming, delivery and document settings. Storing every issued certificate, emailing PDFs as attachments, signing them digitally, or rendering blocks the add-on does not support are larger jobs that our LearnDash services team handles regularly; a LearnDash developer can scope any of them from a description of the delivery flow you want.
Frequently asked questions
How do I make the certificate download instead of opening in the browser?
Return D from learndash_certificate_builder_pdf_output_mode, keeping the default for previews where the certificate ID is zero.
Can I change the file name to include the learner's full name?
Yes. Build it in learndash_certificate_builder_pdf_name from the current user, the course title and the date, and sanitise it with sanitize_file_name().
Can I password-protect certificates?
Yes, through SetProtection() on the mPDF instance filter. Use an empty user password so learners can open the file without a prompt.
Do these hooks affect classic certificates?
No. They run only for certificates built with the builder block. Classic certificates use LearnDash core's TCPDF hooks.
Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.
