keesiemeijer on "Swap title and caption in WP Gallery"

ساخت وبلاگ

Try it with this in your (child) theme's functions.php file. It switches the caption with the post title.

add_filter( 'post_gallery', 'switch_gallery_caption_with_title', 10, 3 );
function switch_gallery_caption_with_title( $gallery, $attr, $instance ) { add_action( 'pre_get_posts', 'disable_suppress_filters' ); add_filter( 'the_posts', 'switch_caption_with_title' ); retu $gallery;
}
function disable_suppress_filters( $query ) { $query->set( 'suppress_filters', false );
}
function switch_caption_with_title( $posts ) { if ( !empty( $posts ) ) { foreach ( $posts as $post ) { $post->post_excerpt = isset( $post->post_title ) ? $post->post_title : ''; } } remove_action( 'pre_get_posts', 'disable_suppress_filters' ); remove_filter( 'the_posts', 'switch_caption_with_title' ); retu $posts;
}

btw:
consider creating a child theme instead of editing your theme directly - if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 102 تاريخ : پنجشنبه 9 ارديبهشت 1395 ساعت: 4:29