Sitemap
Soha Bilal

Soha Bilal

Difficult roads often lead to BEAUTIFUL destination.

WordPress Dynamic List using Shortcode

3 min readJan 17, 2024

If you want to make your list dynamic without using the typical method each time, but with a similar user-friendly interface, here is the shortcode you need to add to your new snippet using the Snippet Code plugin. This feature works seamlessly with your ACF Pro plugin, creating a dedicated section on your edit page/product/blog for easy editing. ACF will help in bringing a separate section to each of your pages accordingly.

Step 1: Add a “repeatable” type field set in ACf, and inside it create a field of type “text” and save it.

Press enter or click to view image in full size

Step 2: Now check your single product/page/blog in edit mode. and watch this section there. Add your list text one by one using “add row” button. after doing this just “update”.

Press enter or click to view image in full size

Step 3: this is important step and for this you need to either use function.php or snippet plugin. I am using snippet to not bring any error in functions.php core files of Wordpress.

Get Soha Bilal’s stories in your inbox

Join Medium for free to get updates from this writer.

just create a snippet and add code in it

add_shortcode(‘show-reason-list-2’, ‘show_reason_list2’);

function show_reason_list2() {
$pageIDr2 = get_the_ID(); // not required if within loop, but doesn’t hurt
$contentr2 = ‘’;
if (have_rows(‘general_reason_list’, $pageIDr2)) {
$contentr .= ‘<div>’;
while (have_rows(‘general_reason_list’, $pageIDr2)) {
the_row();
$contentr2 .= ‘<div style=”width:50%; box-sizing: border-box; float: left; padding: 0 10px; margin-bottom: 8px;”>’;
$contentr2 .= ‘<div class=”elementor-icon-list-item” style=”display: flex;”>’;
$contentr2 .= ‘<span style=”color:#59C925;font-size:12px;” class=”elementor-icon-list-icon”><i aria-hidden=”true” class=”fas fa-check”></i></span>’;
$contentr2 .= ‘<span class=”elementor-icon-list-text” style=”font-family: \’Gilroy Light\’, sans-serif; font-size: 13px;”>’ . esc_html(get_sub_field(‘general_reason_list_2’)) . ‘</span>’;

$contentr2 .= ‘</div>’;
$contentr2 .= ‘</div>’;
}
$contentr2 .= ‘</div>’;
}
return $contentr2;
}

Press enter or click to view image in full size

Step 4: Now open your page where you wanna show the list you created.
you can use “shortcode widget” and paste shortcode in it.
[show-reason-list-2]

Now lastly just check your frontend side and see your list.

Press enter or click to view image in full size

--

--

Soha Bilal
Soha Bilal

Written by Soha Bilal

Difficult roads often lead to BEAUTIFUL destination.