0

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!

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.org/Shortcode_API#Output.
    – jdm2112
    Mar 26 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
    Mar 26 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. Mar 26 at 18:04
  • @jdm2112 I hope I have improved the original post Mar 26 at 18:30
-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.

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.