questions

How to create php shortcode with dynamic link?

Rate this post

I’m having some trouble creating a WordPress shortcode so I can place it under my Elementor page templates.

// Shortcode to output custom PHP in Elementor
function luxis_ics_endpoint($atts) {
    return '<a href="'.<?php echo get_feed_link("calendar"); ?>?id=<?php echo get_the_ID(); ?>"> Download .ics </a>';
        
}
add_shortcode( 'my_elementor_php_output', 'luxis_ics_endpoint');

So the return, I don’t know how to properly write it so that it can take those PHP code and generate a link in the shortcode for me to use at frontend.

Any suggestion will be appreciated!

 

✔️Solution:

Your code looks right. You need to echo the function- not return in this case.

Leave a Reply

Your email address will not be published.

Back to top button