简体   繁体   中英

How to create php shortcode with dynamic link?

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM