Search code examples
phparrayswordpressimplode

Add array attributes to implode()


I don't know PHP, but I have to work in it. I need add to $attr['ids'] array with $gallery_setting.

function the_featured_image_gallery( $atts = array() ) {

    $gallery_setting = get_theme_mod( 'featured_image_gallery' );

    if ( is_array( $gallery_setting ) && ! empty( $gallery_setting ) ) {
        $atts['ids'] = implode( ',', $gallery_setting );

        echo gallery_shortcode( $atts );
    }
}

Ideally, I would like:

echo gallery_shortcode( $atts, array(
  'order'      => 'ASC',
  'size'       => 'full',
  'link'       => 'none'
) );

but I know that it does not work.


Solution

  • Please clarify your question. It's not clear what your problem is...

    To try a shot in the dark:

    function the_featured_image_gallery( $atts = array() ) {
    
        $gallery_setting = get_theme_mod( 'featured_image_gallery' );
    
        if ( is_array( $gallery_setting ) && ! empty( $gallery_setting ) ) {
            $atts['ids'] = implode( ',', $gallery_setting );
    
            $additional_atts = array(
              'order'      => 'ASC',
              'size'       => 'full',
              'link'       => 'none'
            );            
            $atts = array_merge($atts, $additional_atts);
    
            echo gallery_shortcode( $atts );
        }
    }