How can I generate random numbers inside my shortcodes on each implementation?

According to @Mark Kaplun comment: Make your getRandomCode() return value instead of echo like this function getRandomCode(){ $alphanumeric = “0123456789abcdefghijklmnopqrstuvwxyz”; $su = strlen($alphanumeric) – 1; // echo ‘<br/>’; // // echo rand(0, $su); // // echo ‘<br/>’; // // echo substr($alphanumeric, rand(0, $su), 3); // // echo ‘<br/>’; return substr($alphanumeric, rand(0, $su), 3) . substr($alphanumeric, … Read more

Execute shortcode only once in the page

Set a flag like $already_run to static and give it an initial value false. Then check if that value is true. If not, do the one-time thing and then set $already_run to true. The next time this function is called, it will not re-assign the static property, but will instead use the value set at … Read more

shortcode javascript not working on custom template file inside theme folder

You haven’t included get_header() or get_footer() in your template. They will load header.php and footer.php which should include wp_head() and wp_footer(). Those last two functions are important because that’s where scripts are loaded. If your shortcode depends on a script being loaded in the header or the footer, then you need wp_head() or wp_footer(), thats … Read more

How to modify shortcode attributes with data from current post

For anyone who might stumble upon this, I’ve found a solution: In my particular case, I’m using a single-[taxonomy].php template file, and was able to add the shortcode manually via the WordPress function do_shortcode() instead of modifying a shortcode within the post content. Here’s how I wrote it: <?php echo do_shortcode( ‘[mstw_schedule_table sched=”‘.$sports_slug.'” ]’ ); … Read more

Remove wpautop from specific shortcodes only

Well, there is a script out there. The author claims that it removes the wpautop form individual specific shorcodes. You’ll find it here. Add this to your functions.php or your plugin like below- // Here I assumed that you kept the name of the PHP script file same include “shortcode-wpautop-control.php”; And then call the function … Read more

Shortcode produces blank page

I agree that there is a coding error – a blank WP page is almost always caused by a fatal PHP error. You should look at the error.log file in your site’s root folder. That will tell you what/where about the error. If you edit your question to include the error messages found in error.log, … Read more

Demystifying and understanding shortcode nomenclature

It’s just [link to= “https://wordpress.stackexchange.com/”]. This is a textbook example of why extract() is bad. You can’t easily tell where variables are coming from. extract() creates variables out of an array with the keys becoming the variable name. So this part: extract(shortcode_atts(array( “to” => ‘http://net.tutsplus.com’ ), $atts)); Is creating an array with a to key, … Read more

Add custom setting that uses radio button to WP Gallery

I had the same problem and got it finally to work. Based on the thread you have followed, you now have to extend the “update” function of the WP core /wp-includes/js/media-views.js. Go to the “jQuery(document).ready(function()…” part of the ‘print_media_templates’ action and try this: <script> jQuery(document).ready(function() { wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({ // add your custom options template … Read more