How to use shortcodes on a widget sidebar when doing an ajax call?
How to use shortcodes on a widget sidebar when doing an ajax call?
How to use shortcodes on a widget sidebar when doing an ajax call?
When you want to turn a snippet into a shortcode, you have to return a string. You cannot use echo or print anything in any other way. Also, always escape your data, and check if there are actually values. I have used the HEREDOC syntax here, because it is easy to read: add_shortcode( ‘taobao’, ‘taobao_shortcode’ … Read more
What you are looking for is RawHTML to render on the front end. To use a player shortcode in the post you can use the code below remember that the edit function needs to mirror the markup for the save function for Gutenberg to validate the block. Include RawHTML: const { RawHTML } = wp.element; … Read more
That code should work. Are you usign “myclass” as the class and not “.myclass”? Is this for a specific use where class will always be the same? If you’re only looking to ever use this on one place, you can do this: function print_menu_shortcode($atts, $content = null) { extract(shortcode_atts(array( ‘name’ => null, ‘class’ => null … Read more
Version #1 The following seems to work for the Twenty Fifteen theme: /** * Display the comment form via shortcode on singular pages * Remove the default comment form. * Hide the unwanted “Comments are closed” message with CSS. * * @see http://wordpress.stackexchange.com/a/177289/26350 */ add_shortcode( ‘wpse_comment_form’, function( $atts = array(), $content=”” ) { if( is_singular() … Read more
Instead of using the shortcode in the editor, there is a function that executes the shortcode which you can use directly in php of the template for any page. <?php echo do_shortcode(‘[contact_form]’); ?>
You’re getting the output there because dynamic_sidebar() displays/echoes the output (widgets in the specific sidebar), so the output is echoed right when the shortcode function is called, which is before the $data is actually echoed. And you can fix that using output buffering: Either append the output to $data: $data.='</div>’; $data.='<div class=”col-xl-4 col-lg-4 col-md-4 col-sm-12 … Read more
echo (‘<div onClick=”ga(‘send’, ‘event’, ‘will-ich-haben’, ‘klick’, ‘test-klick’);”>’); I haven’t looked any further but as a first step, this string isn’t concatenated correctly. echo “<div onClick=’ga(‘send’, ‘event’, ‘will-ich-haben’, ‘klick’, ‘test-klick’)’></div>”;
If no attributes are used on the shortcode, then $atts will be a string, so you can’t use extract on it. Part of your problem is that you’re not using shortcode_atts correctly. You need to assign the value of shortcode_atts back to $atts. That will ensure that $atts is an array with all the correct … Read more
NEVER EVER alter any template or file in a theme or plugin that you did not author, and this goes for any core file as well. There is no way to protect the code that you alter or add in any of those files, except maybe changing file permissions, but then again, you will run … Read more