Display all post image gallery using the shortcode [gallery]

I want to display the images from the post gallery with the “gallery”. Like that :<?php echo do_shortcode(''); ?>

After some search, I learned that we needed to use a “preg_match” function to get the ids of the images gallery. Something like that :

$post_content = $post->post_content;
preg_match('//', $post_content, $ids);
$array_id = explode(",", $ids[1]);

But I don’t know how to use it … I’m a newbie and it’s quite difficult for me to use that.
Should I put this code in my functions file ? If yes how can I do that please ?

The aim it’s to put a final code like that : <?php echo do_shortcode( '' ); ?>

Thank you and sorry for my english !!!

Source: shortcode

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.