admin管理员组

文章数量:1326308

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/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?

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/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?

Share Improve this question asked Aug 7, 2020 at 16:38 Mohit SinghMohit Singh 1 1
  • 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 Commented Aug 7, 2020 at 17:34
Add a comment  | 

1 Answer 1

Reset to default 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' );

本文标签: phpAdding variable in Wordpress shortcode