admin管理员组文章数量:1326655
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
1 Answer
Reset to default 0Rather 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
版权声明:本文标题:php - Adding variable in Wordpress shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742204705a2432599.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论