Category attribute not working in custom shortcode

So I see two things that could contribute to the problem: I really doubt you’ll need to esc_attr for the query. This is a tricky one, but tax_query needs to be an array of arrays Based on this, I believe this will work better for you: $tax_query = array( ‘taxonomy’ => ‘resources_categories’, ‘field’ => ‘slug’, … Read more

Confused about shortcode and settings values

As you can see in the Shortcode API, there is no jquery involved in evaluating shortcodes. Shortcodes are evaluated on the server side, in PHP, not on the client side with jquery. It is entirely up to you what you do with attributes in the shortcode. If the user writes something like: [demo speed=2000] you … Read more

Get an image’s alt text in a shortcode using the image URL

Instead of using the locationimage attribute, why not use the attachment ID? This will allow you to dynamically grab the URL to the file and will make getting other meta data such as the alt text much easier. Below is a rewritten version of hplocationsfn(). Usage example: [hpLocationSquare id=’2299′ link=’http://example.com’] Note that the link attribute … Read more

get shortcode value

add_shortcode(‘the_chart ‘, ‘high_chart’); function high_chart($atts, $content = null) { //extract the cart and footer_caption value extract(shortcode_atts(array( ‘chart’ => null, ‘footer_caption’ => null), $atts)); /* * process your chart and footer_caption value as * $chart and $footer_caption and return the process data */ $return_html=”chart id:”. $chart.'<br/> Footer Caption:’. $footer_caption; return $return_html } For reference: https://codex.wordpress.org/Function_Reference/add_shortcode Hope … Read more

Add attribute to caption shortcode from custom attachment field

Here’s a solution that leverages the shortcode_atts_{shortcode} filter, where caption is the shortcode in this case. This works by pulling the attachment id from $out[‘id’] then getting the value of the class via get_post_meta( $attachment_id, ‘img_class_field’, true ). With this approach, it is not necessary to modify the output of the caption shortcode in the … Read more

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