admin管理员组文章数量:1300034
I am lost as to how to create a dynamic button shortcode. Depending on the post ID a specific application form is served in a popup by clicking on a button labeled 'Apply'. At the bottom of the page is an apply button (which works). I would like to add another 'Apply' button on the right column with a custom shortcode.
function apply_button($atts, $content = null) {
extract(shortcode_atts(array('link' => '/', 'target' => '' ), $atts));
return '<a class="button" href="'.$link.'" target="'.$target.'">' . do_shortcode($content) . '<span></span></a>';
}
add_shortcode('button', 'apply_button');
How would I add the php addition to the URL in 'link' within the shortcode above?
<?php echo recruitly_get_custom_post_value('jobId'); ?>
I help on what I am missing or done incorrectly would be appreciated!
I am lost as to how to create a dynamic button shortcode. Depending on the post ID a specific application form is served in a popup by clicking on a button labeled 'Apply'. At the bottom of the page is an apply button (which works). I would like to add another 'Apply' button on the right column with a custom shortcode.
function apply_button($atts, $content = null) {
extract(shortcode_atts(array('link' => 'https://recruitly.io/jobs/widget/apply/', 'target' => '' ), $atts));
return '<a class="button" href="'.$link.'" target="'.$target.'">' . do_shortcode($content) . '<span></span></a>';
}
add_shortcode('button', 'apply_button');
How would I add the php addition to the URL in 'link' within the shortcode above?
<?php echo recruitly_get_custom_post_value('jobId'); ?>
I help on what I am missing or done incorrectly would be appreciated!
Share Improve this question edited Mar 26, 2021 at 18:02 Deirdre Nic asked Mar 26, 2021 at 13:41 Deirdre NicDeirdre Nic 451 silver badge8 bronze badges 4- 2 Welcome to WPSE. Try rewording your question so that an informed and specific answer will help you. Describing the exact problem and asking a specific question will help. Rule #1 when creating a shortcode: your function should return a result, not echo it directly. codex.wordpress/Shortcode_API#Output. – jdm2112 Commented Mar 26, 2021 at 14:49
- Another rule when creating a shortcode: You have to name it. (The first parameter can't be empty, which is what you've got in your code.) – Pat J Commented Mar 26, 2021 at 15:41
- Apologies lads I have tidied that up somewhat above in my original comment and updated the text. I hope it makes a bit more sense now. – Deirdre Nic Commented Mar 26, 2021 at 18:04
- @jdm2112 I hope I have improved the original post – Deirdre Nic Commented Mar 26, 2021 at 18:30
1 Answer
Reset to default -1This may not be a direct answer to your shortcode issue. But try doing it as a post template, from there its easier to handle post data.
You have a working button below the description. Copy it and place it on the bottom. And use Class to trigger your JS this time.
本文标签: phpCustom Shortcode with Dynamic Button
版权声明:本文标题:php - Custom Shortcode with Dynamic Button 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741652193a2390545.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论