Adding to the_content or a variable from within a shortcode function

I think, I would simply store all the definitions during the glossary_shortcode() execution in a global variable and serve them at the end of some hook like the_content. function glossary_shortcode( $atts = array(), $shortcode_content = null ) { // Your code can be kept identical, just store the $glossary_term_object somewhere. global $glossaries; $glossaries = $glossaries … Read more

Where to filter Shortcode string prior to execution

shortcode_atts_{$shortcode} seems to be the WordPress filter you need. https://developer.wordpress.org/reference/hooks/shortcode_atts_shortcode/ It is used in the shortcode_atts() function: https://developer.wordpress.org/reference/functions/shortcode_atts/

Use shortcodes in terms description? [closed]

I believe the following should work: <?php $content = apply_filters(‘the_content’, $content); $content = str_replace(‘]]>’, ‘]]&gt;’, $content); ?> You could put this in the template of in a hooked functions. I’ve cribbed this from here and here, where the intention is to write content from get_the_content() (raw) in an equivalent way to the_content() (amongst other things: … Read more

Shortcodes attributes defaults

I have no idea what goes wrong at your setup. Clearly shortcode is properly registered, but some specific case something prevents it from being parsed correctly. This is test code that roughly replicates how shortcode is parsed for execution : $content = get_option(“prc_speciall_offer_text”, true); $pattern = “https://wordpress.stackexchange.com/”.get_shortcode_regex().’/s’; preg_replace_callback( $pattern, ‘var_dump’, $content ); Array output should … Read more

WordPress wpautop/shortcode generating invalid markup

Try this: // replaces [banner …] .. [/banner] with <!–banner ID–> before the_content filters run add_filter(‘the_content’, ‘protect_my_shortcode’, -100); function protect_my_shortcode($content){ return preg_replace_callback(‘/\[(banner)\b(.*?)(?:(\/))?\](.+?)\[\/\1\]/s’, ‘protect_my_shortcode_callback’, $content); } function protect_my_shortcode_callback($matches){ global $__banners; $id = ‘<!–banner ‘.count($__banners).’–>’; $__banners[$id] = do_shortcode($matches[0]); // or ‘[‘.$matches[1].’ ‘.$matches[2].’]’.$matches[4].'[/’.$matches[1].’]’ // if you need to run any filters on the shortcode content ($matches[4]) return $id; … Read more

Changing the title tag from a shortcode

You are correct in your thinking that because the loop evaluates after the header you will not be able to get the contents of the loop there. The easiest way to do this is probably with jQuery. Something like this: <script type=”text/javascript”> $(document).ready(function() { document.title=”blah”; }); </script> Place this code in your loop, and the … Read more

Button Shortcode

How about this? <?php function btn($atts, $content = null) { extract(shortcode_atts(array(‘link’ => ‘#’, ‘color’ => ‘teal’ , ‘size’ => ‘large’), $atts)); return ‘<a class=”btn ‘.$size.'” href=”‘.$link.'” style=”background:’.$color.’;”><span>’ . $content . ‘</span></a>’; } add_shortcode(‘btn’, ‘btn’); ?>

Shortcode help: If no image entered take default

add a conditional statement before the line with ‘return’, for example: if( $imgURL == ‘paste Img Url’ ) $imgURL = get_stylesheet_directory_uri().’/images/default.jpg’; http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)