web-dev-qa-db-fra.com

Afficher la galerie avant le contenu

Est-il possible d'exécuter le shortcode de la galerie avant tout autre contenu, peu importe où se trouve le shortcode dans l'article HTML?

function gallery_first( $content) {
    $expr = '/\[gallery(.*?)\]/i';
    return preg_replace_callback( $expr, create_function('$matches', 'return do_shortcode($matches[0]);'), $content);
}
add_filter( 'the_content', 'gallery_first', 6); // prio 6 executes this function previous to all other filter functions
2
jot
function gallery_first( $content) {
    $expr = '/\[gallery(.*?)\]/i';
    return (" [gallery] " . preg_replace( $expr, '', $content)); // deletes all existing gallery shortcodes
}
add_filter( 'the_content', 'gallery_first', 6); // level '6' executes this function previous to all other filter functions
1
jot