• Auraya86

    (@auraya86)


    Hi,

    I have a very strange effect in my custom shortcode.
    I want to build an accordion on different content pages via shortcode. But I can’t execute the js multiple times, just one time on initial load.

    I can’t create the accordion via css, because my input fields are NOT in the DOM. So it can’t be an css problem.

    This is how I add the shortcode-accordion

    function add_accordion($atts){
        $a = shortcode_atts( array(
              'id' => '',
              'class' => ''
           ), $atts );
    
            ob_start();
    
            wp_enqueue_script( "accordionjs" );
    
            set_query_var( 'post_id', absint( $a['id']) );
            set_query_var( 'class',  $a['class'] );
    
           get_template_part('template-parts/accordion');
    
            return ob_get_clean();
    }
    
    add_shortcode( 'accordion', 'add_accordion' );

    In my accordion.php I am not able to render a simple checkbox like this:
    <input type="checkbox" name="chk1" id="chk1" />

    Where are my input field or the script tags for javascript?
    I am using AngularJS with the current WordPress-Version.

    Do you know this problem?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Hi!

    Where are you registering the script accodionjs from?

    Thread Starter Auraya86

    (@auraya86)

    Thanks for your time Jose!!

    After searching several days for the solution, I actually found the problem today accidently and on my own 🙂 It was just an angular problem.

    I included the wordpress content via angular. I used the ng-bind-html Attribute for it. With the compile-directive (see link below) the input fields and javascript works fine again!!

    Please see here how the compile directive works.

    ng-click on element inserted using ng-bind-html not firing
    byu/jp246 inangularjs

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Ah, that would do it, lol

    Be sure to mark it as resolved so others know it is 😀

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Shortcode doesnt render checkbox’ is closed to new replies.