Skip to content

Instantly share code, notes, and snippets.

@adeel-raza
Created March 9, 2024 23:12
Show Gist options
  • Save adeel-raza/551e5fbf510286cb6ac3f1500bc85ffe to your computer and use it in GitHub Desktop.
Save adeel-raza/551e5fbf510286cb6ac3f1500bc85ffe to your computer and use it in GitHub Desktop.
Show LearnDash Certificate Link For User By Certificate ID - Custom Shortcode
if ( isset( $_GET['user_id'] ) && $_GET['ld_certificate'] ) {
include_once LEARNDASH_LMS_PLUGIN_DIR . 'includes/ld-convert-post-pdf.php';
learndash_certificate_post_shortcode(
$cert_args = array(
'user_id' => esc_attr(
$_GET['user_id']
),
'cert_id' => esc_attr(
$_GET['ld_certificate']
),
'post_id' => esc_attr(
$_GET['ld_certificate']
),
),
);
die;
}
function learndash_get_certificate_link_by_user_id( $atts ) {
// Extract shortcode attributes
$atts = shortcode_atts( array(
'user_id' => get_current_user_id(),
'ld_certificate' => '',
), $atts );
// Retrieve attribute values
$user_id = $atts['user_id'];
$cert_id = $atts['ld_certificate'];
$cert_link = get_permalink( $cert_id );
$certificate = get_post( $cert_id );
$cert_query_args = array(
'user_id' => ( $user_id ? $user_id : get_current_user_id() ),
'ld_certificate' => $cert_id,
);
$url = add_query_arg( $cert_query_args, $cert_link );
return '<a rel="noopener" target="_blank" href="' . esc_url_raw( $url ) . '">' . esc_html( $certificate->post_title ) . '</a>';
}
add_shortcode( 'ld_cert_by_user', 'learndash_get_certificate_link_by_user_id' );
@adeel-raza
Copy link
Author

adeel-raza commented Mar 9, 2024

  1. Place the above snippet in your theme's functions.php file
  2. Add this shortcode to any of your pages or post to show the certificate link.

[ld_cert_by_user ld_certificate="{your_ld_certificate_post_id}"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment