Shortcode parsed incorrectly because of heredoc

A workaround might be: [code] $foo = &lt;&lt;&lt;EOT …. EOT; [/code] where we change <<< to &lt;&lt;&lt;. We could do this automatically before do_shortcode filters the content and then replace it again afterwards. I tested this version: [code] $foo = <<<EOT …. EOT;<!—-> [/code] and it seems to parse the shortocde’s content correctly. But then … Read more

How to Get a part of URL and put in shortcode?

This should work: function get_name() { $url = “http://domain.com/author/peter”; if (preg_match(“/author/”, $url )) { $lastSlash = strrpos( $url, “https://wordpress.stackexchange.com/”); return substr( $url, $lastSlash, strlen($url)); } } This will return everything after the last slash.

Shortcode not working on static front page

It looks like you need to change your front-page.php page, you are using the wrong variable. $static_page_content = get_the_content(); to $static_page_content = the_content(); Edit: I see you just updated your question to this, yes this will work fine. Shouldn’t see any negative side effects from this.

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