jQuery(document).ready(function($) { // Generate upId for all shortcodes on the page const UP_ID = Math.floor(Math.random() * (999999999 - 100000000) + 100000000); // Get pagetype and tp from meta tag if they exist let pagetype = document.querySelectorAll('meta[property="og:type"]')[0]?.content; // Loop through all the medusa tags and request their content $('.ta-medusa-section-config').each(function() { // Get data from shortcode output let attr = $(this).data('medusa-attributes'); // Add the additional data to object attr.upId = UP_ID, attr.pagetype = pagetype; // Make AJAX request to get rendered layout $.ajax({ url: medusa_ajax.url, type: 'POST', data: { 'action': 'medusa_build_layout', 'data': JSON.stringify(attr) }, success: (response) => { // Replace the placeholder with the result returned from AJAX $(this).replaceWith(response); } }); }); });