Shortcode to Gutenberg-block: additional text on front-end and conditional display

Although a little different than I had initially anticipated, I have found/created a solution to my two problems. Conditionals I have opted to move non-required input to the sidebar, using the InspectorControls-element. Reason for this is that I realised that it would be impossible to hide a field (in the editor-part of the screen) that … Read more

Ajax not returning anything on form submit

Shortcodes are too late to add ajax actions. Additionally, that actions would be added only if shortcode is executed, which is very unlikely to happen on a ajax request. The quickest way to make your code work is to move the add_action outside addimage() function. add_action( ‘wp_ajax_wp_up’, ‘wp_up’ ); add_action( ‘wp_ajax_nopriv_wp_up’, ‘wp_up’); function wp_up() { … Read more

How to get shortcode to work inside a foreach loop called within a shortcode?

The issue is you are echoing raw post_content field from object. It isn’t what usually gets to front-end. Try: apply_filters( ‘the_content’, $post->post_content ) If you want to run shortcodes alone (without bunch of other filters) you can do: do_shortcode( $post->post_content ) Edit re-read your question… Is there a possibility that this thing gets recursive? Post … Read more

Format content value from DB outside of WordPress filters

There are a few filters and actions here that run. You’d need to look at the code and figure out what/how to utilize these. https://codex.wordpress.org/Function_Reference/wpautop https://codex.wordpress.org/Function_Reference/wptexturize https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content https://developer.wordpress.org/reference/functions/do_shortcode/ https://developer.wordpress.org/reference/functions/unescape_invalid_shortcodes/ https://developer.wordpress.org/reference/functions/get_shortcode_regex/

Get shortcode attributes outside shortcode function

You can pass an array to your script with wp_localize_script($handle, $object_name, $l10n). function test_function( $atts ) { $data = shortcode_atts( array ( ‘arrows’ => TRUE ), $atts ); wp_enqueue_script( ‘your_script_name’ ); wp_localize_script( ‘your_script_name’, ‘yourScriptObject’, $data ); return ‘a string’; } In your (external) script you can access the shortcode data now with … var arrows … Read more

Shortcode returns escaped HTML tags

I would recommend using single quotes if you want to include some HTML, also you need to return something otherwise nothing happens. // WP Shortcode function text_shortcode() { return ‘<strong>bold text:</strong> <a href=”https://wordpress.stackexchange.com/questions/318934/shortcode-returns-escaped-html-tags”>See wordpress.stackexchange.com</a>’; } add_shortcode(‘bold-text’, ‘text_shortcode’); Your WordPress shortcode would be: [bold-text] Edit: You don’t need html_entity_decode or htmlentities only when you’re doing something … Read more

Getting attribute value from shortcode

I read your question differently than @eric-holmes. It sounds to me like your shortcode needs to function normally under most circumstances but that you are extracting information in special circumstances. Shortcode regex is tricky. Let WordPress do it for you. $pattern = get_shortcode_regex(); preg_match_all(“/$pattern/”,$wp_content,$matches); Your attributes for any shortcodes present in $wp_content should now be … Read more