WordPress 4.7 Galery shortcode not working

my gallery shortcode is working wp 4.00 version but ı upgrade wp.4.7 not working how can i fix . why not working ? when i delete this function ,normal wp shortcode function not working . this is my shortcode function:

remove_shortcode('gallery', 'gallery_shortcode');
add_shortcode('gallery', 'magicreche_post_gallery');
function magicreche_post_gallery($attr) {

    wp_enqueue_script('hoverdir');

    $post = get_post();

    static $instance = 0;
    $instance++;

    if ( ! empty( $attr['ids'] ) ) {
        // 'ids' is explicitly ordered, unless you specify otherwise.
        if ( empty( $attr['orderby'] ) )
            $attr['orderby'] = 'post__in';
        $attr['include'] = $attr['ids'];
    }

    // Allow plugins/themes to override the default gallery template.
    $output = apply_filters('post_gallery', '', $attr); // burası
    if ( $output != '' )
        return $output;

    // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
    if ( isset( $attr['orderby'] ) ) {
        $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
        if ( !$attr['orderby'] )
            unset( $attr['orderby'] );
    }

    extract(shortcode_atts(array(
        'order'      => 'ASC',
        'orderby'    => 'menu_order ID',
        'id'         => $post ? $post->ID : 0,
        'itemtag'    => 'li',
        'icontag'    => '',
        'captiontag' => 'span',
        'columns'    => 3,
        'size'       => 'gallery',
        'include'    => '',
        'exclude'    => '',
        'link'       => ''
    ), $attr, 'gallery'));

    $id = intval($id);
    if ( 'RAND' == $order )
        $orderby = 'none';

    if ( !empty($include) ) {
        $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );

        $attachments = array();
        foreach ( $_attachments as $key => $val ) {
            $attachments[$val->ID] = $_attachments[$key];
        }
    } elseif ( !empty($exclude) ) {
        $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
    } else {
        $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
    }

    if ( empty($attachments) )
        return '';

    if ( is_feed() ) {
        $output = "\n";
        foreach ( $attachments as $att_id => $attachment )
            $output .= wp_get_attachment_link($att_id, 'full', true);
        return $output;
    }

    $columns = intval($columns);
    switch ($columns) {
        case '10':
        case '9':
        case '8':
        case '7':
        case '6':
        case '5':
        case '4':
            $itemwidth="col-sm-3";
            $row_break = 4;
            break;
        case '3':
            $itemwidth="col-sm-4";
            $row_break = 3;
            break;
        case '2':
        case '1':
            $itemwidth="col-sm-6";
            $row_break = 2;
            break;

        default:
            $itemwidth="col-sm-3";
            $row_break = 3;
            break;
    }

    $selector = "gallery-{$instance}";

    $size_class = sanitize_html_class( $size );
    $gallery_div = '<ul id="' . $selector . '" class="gallery gallery-columns-' . $columns . ' gallery-size-' . $size_class . '">';
    $output = $gallery_div;

    $i = 0;

    foreach ( $attachments as $id => $attachment ) {

        $i = $i + 1;

        $thumb = wp_get_attachment_image_src( $id, 'gallery', false );
        $full = wp_get_attachment_image_src( $id, 'full', false );

        $image_output="<a href="" . $full[0] . '" title="' . wptexturize($attachment->post_excerpt) . '" class="fancybox" data-fancybox-group="' . $selector . '" rel="gallery"><img src="' . $thumb[0] . '"><span><i class="fa fa-search fa-3x"></i></span></a>';

        $image_meta = wp_get_attachment_metadata( $id );

        $output .= '<li class="gallery-item ' . $itemwidth . '">';
        $output .= $image_output;
        $output .= '</li>';

    }

    $output .= '</ul>';

    return $output;
}

0

Leave a Comment