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
Add a comment  | 

1 Answer 1

Reset to default -1

This 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