How to give Wordpress shortcode a dynamic Atribute?

Viewed 18

I have build many shortcode to show somme data from a training cours. If y put a value, it works well.

[TEST_PHP cours = <script>document.write("1")</script>]

But if I try to use a const or a global var for the value, It doesent work, coursID = "" ?


<script>
    const coursID = "1";
</script>

[TEST_PHP cours = <script>document.write(coursID)</script>]

How to call a shortcode in Javascript with a const als attribute ?

1 Answers

example of shortcode

<?php 
function getgenie_elementor_render_shortcode( $atts ) {
    $attributes = shortcode_atts( array(
        'content_id' => 0,
    ), $atts );
    
    $content_id = $atts['content_id'];

    if ( !class_exists( '\Elementor\Plugin' ) ) {
        return 'builder not found';
    }

    if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
        $css_file = new \Elementor\Core\Files\CSS\Post( $content_id );
        $css_file->enqueue();
    }
    
    $elementor_instance = \Elementor\Plugin::instance();

    return $elementor_instance->frontend->get_builder_content_for_display( $content_id );

}
add_shortcode( 'getgenie_elementor_render', 'getgenie_elementor_render_shortcode' );
Related