I use WordPress with Cornerstone and Essential Grid.
I want to setup a page template which has an URL-parameter, eg: localhost/info/template/?id=1
On this page I have an essential grid.
When id =1 I want to show essential grid mygrid1, when id = 2 I want to load grid mygrid2.
I tried to replace the shortcode with
document.getElementById("myGrid").innerHTML= mynewGrid
But at this point, the grid is already initialized and I am too late. Also replace shortcode in functions.php (child theme) is too late. So I made a new plugin. I had the intention that my new plugin loads before the essential grid plugin loads.
function createDynamicContent(string $content)
{
if (is_page('1209')) {
Do the processing etc…
Load the new shortcode from DB, based on the url-parameter
then replace the dummy-shortcode with the real new shortcode using $content
the dummy shortcode is mydummy
the $mynewgrid is the string for the new grid [ess_grid alias="berge"][/ess_grid]
$newContent= str_replace("mydummy", $mynewgrid, $content);
$content = $newContent;
return $content;
}
I added this function :
add_filter('the_content', 'createDynamicContent', 10);
I also tried
add_action( 'the_content', 'createDynamicContent', 100, 3);
When I set the priority parameter to 100 the dummy is replaced in the source but the grid is not loaded.
When I set the priority parameter to 1, the page breaks.
Do I have a chance to dynamically replace the shortcode?