0

I have this shortcode [post color="XYZ" width="980" height="610]

I wish to pass $color in color="". Here, $color is fetched from dynamic URL: www.mydomain.com/check/?color=BLUE $color is working fine otherwise, but I wish to pass it in the shortcode so that color is dynamically loaded on the page based on $color

How could this be achieved?

  • Your question isn't clear. Do you want this parameter to come from the shortcode or the URL? What does your current shortcode code look like? – mozboz Aug 7 at 17:34
0

Rather than passing the variable contents in to the shortcode, you would probably be better to pass in the URL parameter you are setting, i.e. [post color="color" width="980" heigh="610"]. Because your shortcode will execute during load in PHP, you can then tell your shortcode function to store the value of $_GET['color'] to later use in that function.

You might do this like:

function build_the_thing( $atts ) {
    $pageColorURL = $_GET[$atts['color']];
    return $pageColorURL;
}
add_shortcode( 'post', 'build_the_thing' );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.