LMS & eLearning

Building a Certificate Verification Page for LearnDash

LearnDash has no public way for an employer to check a certificate. A design and working code for issuing a verification code at completion, printing it on the PDF and looking it up safely.

Building a Certificate Verification Page for LearnDash

A certificate is only worth what a third party can check. LearnDash 4.18.0.1 secures certificate downloads for the learner with a nonce, but it has no public page where an employer or regulator can type a code and confirm that a certificate is genuine. The certificate URL cannot serve that purpose: it is tied to the learner's login and renders a PDF, not a confirmation. This guide designs a verification system on top of LearnDash's completion hooks and gives working code: a code issued at completion, printed on the certificate, and checked on a public page that reveals only what a verifier needs.

Design decisions

  • Issue the code at completion, not at download. PDFs are generated on every request, so a hook inside PDF generation would run many times and sometimes never. The learndash_course_completed action fires once when the course status becomes complete, with the user, the course and the completion time.
  • Store it in user meta keyed by course. A code per user per course is enough for most programmes and avoids a custom table. Sites with many thousands of completions or that need to revoke certificates should use a table with an index on the code.
  • Make the code unguessable but typeable. Ten characters from an unambiguous alphabet gives far more combinations than anyone can enumerate through a rate-limited form, and still fits on a certificate.
  • Show the minimum. The verification result should confirm the holder's name as printed, the course title and the completion date. It should not reveal email addresses, scores or other courses.

Step 1: issue a code on completion

<?php
/**
 * Issue a verification code when a course is completed.
 */
add_action(
    'learndash_course_completed',
    function ( $data ) {
        $user_id   = (int) $data['user']->ID;
        $course_id = (int) $data['course']->ID;
        $meta_key  = 'wwc_cert_code_' . $course_id;

        if ( get_user_meta( $user_id, $meta_key, true ) ) {
            return; // Keep the original code on re-completion.
        }

        $alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
        do {
            $code = '';
            for ( $i = 0; $i < 10; $i++ ) {
                $code .= $alphabet[ random_int( 0, strlen( $alphabet ) - 1 ) ];
            }
            $exists = get_users(
                array(
                    'meta_key'   => $meta_key,
                    'meta_value' => $code,
                    'fields'     => 'ID',
                    'number'     => 1,
                )
            );
        } while ( ! empty( $exists ) );

        update_user_meta( $user_id, $meta_key, $code );
        update_user_meta( $user_id, 'wwc_cert_code_issued_' . $course_id, (int) $data['course_completed'] );
    },
    20,
    1
);

For learners who completed courses before this code was installed, run a one-off WP-CLI loop over users and completed courses that calls the same logic, or let the certificate shortcode below issue a code lazily when it finds none.

Step 2: print the code on the certificate

Register a shortcode that reads the code for the course the certificate is being rendered for. On a classic certificate the course ID is in the URL as course_id, and when an administrator views a learner's certificate LearnDash switches the current user before rendering, so get_current_user_id() is the learner:

<?php
add_shortcode(
    'wwc_cert_code',
    function () {
        $course_id = isset( $_GET['course_id'] ) ? absint( $_GET['course_id'] ) : 0;
        $user_id   = get_current_user_id();
        if ( ! $course_id || ! $user_id ) {
            return '';
        }
        $code = get_user_meta( $user_id, 'wwc_cert_code_' . $course_id, true );
        return $code ? esc_html( $code ) : '';
    }
);

Add a line such as Verify at example.com/verify with code [wwc_cert_code] to the certificate content, or a QR code image generated from that URL by a library, drawn with learndash_certification_after as described in the certificate hooks reference. The builder's paragraph block runs shortcodes too, so the same shortcode works in the Certificate Builder.

Step 3: the public verification page

<?php
add_shortcode(
    'wwc_verify_certificate',
    function () {
        $code   = isset( $_GET['code'] ) ? strtoupper( preg_replace( '/[^A-Za-z0-9]/', '', wp_unslash( $_GET['code'] ) ) ) : '';
        $result = '';

        if ( '' !== $code ) {
            $ip    = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : 'none';
            $tries = (int) get_transient( 'wwc_verify_' . md5( $ip ) );
            if ( $tries > 20 ) {
                return '<p>' . esc_html( 'Too many attempts. Try again later.' ) . '</p>';
            }
            set_transient( 'wwc_verify_' . md5( $ip ), $tries + 1, HOUR_IN_SECONDS );

            global $wpdb;
            $row = $wpdb->get_row(
                $wpdb->prepare(
                    "SELECT user_id, meta_key FROM {$wpdb->usermeta} WHERE meta_key LIKE %s AND meta_value = %s LIMIT 1",
                    $wpdb->esc_like( 'wwc_cert_code_' ) . '%',
                    $code
                )
            );

            if ( $row && preg_match( '/^wwc_cert_code_(\d+)$/', $row->meta_key, $m ) ) {
                $course_id = (int) $m[1];
                $user      = get_userdata( (int) $row->user_id );
                $issued    = (int) get_user_meta( $user->ID, 'wwc_cert_code_issued_' . $course_id, true );
                $result    = '<div class="wwc-verify-ok"><p>' . esc_html( 'Valid certificate.' ) . '</p><ul>'
                    . '<li>' . esc_html( 'Name: ' . $user->display_name ) . '</li>'
                    . '<li>' . esc_html( 'Course: ' . get_the_title( $course_id ) ) . '</li>'
                    . '<li>' . esc_html( 'Completed: ' . wp_date( get_option( 'date_format' ), $issued ) ) . '</li>'
                    . '</ul></div>';
            } else {
                $result = '<p class="wwc-verify-fail">' . esc_html( 'No certificate matches that code.' ) . '</p>';
            }
        }

        $form = '<form method="get"><label for="wwc-code">' . esc_html( 'Certificate code' ) . '</label> '
            . '<input id="wwc-code" name="code" type="text" maxlength="12" value="' . esc_attr( $code ) . '"> '
            . '<button type="submit">' . esc_html( 'Verify' ) . '</button></form>';

        return $form . $result;
    }
);

Create a page at /verify/ with [wwc_verify_certificate]. The transient limits each address to a modest number of lookups per hour, which, combined with the code length, makes guessing impractical. The query is a prefix match on the meta key, which is fine for user meta tables up to a few hundred thousand rows; beyond that, move to a dedicated table.

Testing the whole loop

Complete a course with a test learner and confirm two meta rows appear for that user. Open the certificate and check that the code prints; if it is blank, the certificate was opened before the completion hook ran, which happens when an administrator marks the course complete from the profile screen, because that path also fires the hook but after the page has rendered. Reload and it should appear. Then, in a private browser window with no login, open the verification page, enter the code with and without spaces and in lower case, and confirm the normalised code matches. Finally enter a wrong code twenty-five times to see the rate limit respond, and wait for the transient to expire before continuing.

Keep the verification page out of the LearnDash login redirect and any membership plugin's content protection; it has to be reachable by someone who has no account. A cached page is fine for the empty form, but exclude requests with a code parameter from full-page caching so results are never served to the wrong visitor.

Revocation and expiry

To revoke a certificate, delete the two meta values for that user and course; the page then reports no match. For certificates that expire, store the expiry alongside the issue date and have the page show "expired" rather than "valid" once it passes. If you use LearnDash's course access expiration with data deletion for recertification, keep the verification meta independent of course progress, as it is here, so a renewed certificate issues a new code while the old one can be kept or revoked deliberately.

Quiz and group certificates

The same pattern applies with learndash_quiz_completed, which receives the attempt data and the user, keyed by quiz ID and attempt time, and with a group completion check. Most programmes verify the course or programme certificate only, so start there. The certificate types comparison helps decide which certificate is the credential.

When to get help

Verification with QR codes, a public registry page listing credential holders who opted in, or integration with an external credentialing service are development projects our LearnDash services team takes on; a LearnDash developer can also move the code store to a custom table with revocation history for accredited programmes, and our API development and integration team handles the external registry side.

Frequently asked questions

Does LearnDash have built-in certificate verification?

No. Certificate URLs are secured for the learner's own download and do not confirm authenticity to a third party. A small verification system on the completion hook fills the gap.

It contains a nonce tied to the learner and the viewer, renders a PDF rather than a confirmation, and shows nothing to a logged-out visitor.

Can the code be a QR code?

Yes. Generate a QR image for the verification URL with the code and draw it on the PDF with the learndash_certification_after hook, or place it in a builder image block.

What personal data should the page show?

Only the name as printed, the course and the completion date. Never email addresses, scores or a list of other courses.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Free consultation

Need help with LearnDash?

Tell us what you are working on. A developer who does this every week reads your message and replies within one business day with next steps and a free quote.

  • Free consultation and quote
  • NDA on request
  • You own the source code
  • Reply within one business day

Tell us about your project

Add budget and timeline optional, helps us quote faster

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.