Hello,
I am trying to create shortcodes in an easy way for my cms I am successfull to create and replace the shortcode with the content but what if there will be 2 shortcodes placed within the content I am confused to replace it if there are 2 shortcodes can anyone help me out with this please thank you for your help in advance
$content = "Hello world this is a lorem ipsum text [shortcode id='generate'] this is used for some [shortcode id='maximum'] dummy words";
preg_match_all("/\[(.*?)\]/", $content, $matches);
foreach($matches[1] as $match) {
if(is_array($match)) {
foreach($match as $value) {
echo $value . "<br />";
$id = explode('shortcode id=', $value);
}
} else {
$match . "<br />";
$id = explode('shortcode id=', $match);
echo $id[1] . "<br />";
$cleantext = str_replace("'", "", $id[1]);
$var = array($cleantext);
}
}
echo str_replace("$cleantext", "Shortcode displayed", $content);
The problem is that I am really much confused about my code as well in this code it is only replacing it with the first one second one is not coming up as it is an array so can any one let me know how do I do this?