Nested Shortcode Inside [caption] Doesn’t Process

There is a hook inside the caption shortcode that will allow you to hijack the whole thing. Most of the following is copied from the Core img_caption_shortcode function. function nested_img_caption_shortcode($nada, $attr, $content = null) { extract( shortcode_atts( array( ‘id’ => ”, ‘align’ => ‘alignnone’, ‘width’ => ”, ‘caption’ => ” ), $attr, ‘caption’ ) ); … Read more

How do I add my own custom shortcodes?

Shortcodes work via Shortcode API. Essentially shortcode is just a human-friendly form of writing out data that is processed and passed to associated PHP function. So adding your own shortcode involves: Coding PHP function that would process data, passed by API from shortcode. Registering that function as shortcode handler. I also remember WP Utility Short … Read more

Run shortcode at certain resolution

Ok, let’s clarify the concept. You don’t want download the content for mobile device, and you want to rely on screen resolution. You know that php (wordpress) run on server, screen resolution is a completely client-side matter. So the flow will be: user send a request to your site your site page load on client … Read more

display shortcodes outside of the_content

You can use the function do_shortcode() for use shortcodes outside fomr default content. You can also parse this in your function, there get the output of your textfields, like the follow example for a custom field: if ( get_post_meta( $post->ID, ‘cfield’, TRUE ) ) echo do_shortcode( get_post_meta( $post->ID, ‘cfield’, $single = TRUE ) );

Why does WP not like my container?

I think it’s safe to say that wpautop() is a basket case without hurting anyone’s feelings, but I wouldn’t remove & add it at a different priority as that just makes things worse, as demonstrated (although what you posted is the browser trying to make sense of broken html, rather than the actual output, which … Read more

How to return a string that has a variable inside in a shortcode?

When you want to return a data combined with a string, you can use one of the following methods: Either open and close the string using ‘: return ‘<span class=”class2″ id=”class3-‘ . $random . ‘”> </span>’; Or use the double quote: return “<span class=”class2″ id=’class3-{$random}’> </span>”; You can simply use $random without the {} curly … Read more

WP_Query in a shortcode

When you are constructing the $output variable, you need to consider get_the_post_thumbnail() get_the_excerpt() get_the_content() get_permalink() that return the values instead of the_post_thumbnail() the_excerpt() the_content() the_permalink() that echo the values.

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

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