WordPress.org

Ready to get started?Download WordPress

Forums

Accordion Shortcode
Collapse all (11 posts)

  1. jdev
    Member
    Posted 2 years ago #

    Is there a way to collapse all content in the accordion by default?

    http://wordpress.org/extend/plugins/accordion-shortcode/

  2. blueairplane
    Member
    Posted 2 years ago #

    Great plugin - but I'm really trying to do the same - anyone have luck with this?

    Using [accordions active=0] just doesn't do anything.

    Thanks for any ideas!

  3. bdell
    Member
    Posted 2 years ago #

    I am needing the same thing!

  4. AndyWarren
    Member
    Posted 1 year ago #

    For this plugin to show all of the accordion items as collapsed when the page first renders you need to make a couple changes to the plugin code. I had the same issue as you guys for about an hour today. Open your plugins directory and then open the accordion-shortcode directory, and then finally open accordion-shortcode.php.

    Look for this line, its line 53 in my editor:
    $attr['active'] = (int)$attr['active'];

    Change it to:
    $attr['active'] = (bool)$attr['active'];

    Then look for this line, its line 61 in my editor:
    'active' => 0,

    Change it to:
    'active' => false,

    Then on your accordion, make sure you set the shortcode to:
    [accordions collapsible=true]

    This just worked for me, hope it helps.

  5. stacey6
    Member
    Posted 1 year ago #

    awarren - Thanks for posting this. Worked like a charm!!!

  6. akhayyat
    Member
    Posted 1 year ago #

    Found an easier workaround: Use a very large value for active:

    [accordions active=100 collapsible=true]

  7. vijilov
    Member
    Posted 1 year ago #

    hey i tried -1. its working!
    try this,

    [accordions active=-1]

  8. akhayyat
    Member
    Posted 1 year ago #

    For me, -1 expands the last accordion.

    The only thing that works for me is:

    [accordions active=100 collapsible=true]

    (assuming you have fewer than 100 accordions)

  9. Peterkopi
    Member
    Posted 1 year ago #

    I am also trying to have all collapsed when the page is loaded, but the script must have been edited, because I can't find

    $attr['active'] = (int)$attr['active'];

    on line 53, which now is showing:

    'class' => null,

    akhayyat's workaround did NOT work for me.

    Can anybody help, please?

  10. Peterkopi
    Member
    Posted 1 year ago #

    In version Version: 1.2.1 I can find this on line 101-130:

    public static function accordions_shortcode( $atts, $content ) {
    
    		self::$add_script = true;
    		if( is_string($atts) )
    			$atts = array();
    
    		$attr['autoHeight'] = self::eval_bool( $atts['autoheight'] );
    		$attr['disabled']  	= self::eval_bool( $atts['disabled'] );
    		$attr['active']  	= (int)$atts['active'];
    		$attr['clearStyle'] = self::eval_bool( $atts['clearstyle']);
    		$attr['collapsible']= self::eval_bool( $atts['collapsible']);
    		$attr['fillSpace'] 	= self::eval_bool( $atts['fillspace']);
    
    		$query_atts = shortcode_atts( array(
    				'autoHeight'  => false,
    				'disabled'   => false,
    				'active'  => 0,
    				'animated'   => 'slide',
    				'clearStyle'  => false,
    				'collapsible'  => false,
    				'event'   => 'click',
    				'fillSpace'  => false
    			), $attr);
    		$id = "random-accordion-id-".rand(0,1000);
    
    		$content = str_replace( "]<br />","]", ( substr( $content, 0 , 6 ) == "<br />" ? substr( $content, 6 ): $content ) );
    
    		self::$shortcode_js_data[$id] = $query_atts;
    
    		return str_replace("\r\n", '', '<div id="'.$id.'" class="accordions-shortcode">'.do_shortcode( $content ).'</div>');

    Maybe it's somewhere around here I need to change the script to laod collapsed?

  11. AndyWarren
    Member
    Posted 1 year ago #

    @Peterkopi -

    Change your line 109 to $attr['active'] = (bool)$attr['active'];

    Then change your line 117 to 'active' => false,

    And Finally, display your accordion with [accordions collapsible=true] as the opening shortcode. Let me know if this works, I haven't used this plugin for quite some time.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic