Support » Plugin: Shortcake (Shortcode UI) » How to use SHORTCODE_UI_DOING_PREVIEW?

  • Hi!

    I’m trying to setup a different view for my shortcode on TinyMCE, like a placeholder. From what I saw, there’s the SHORTCODE_UI_DOING_PREVIEW constant to help doing that. I’m using this code on my shortcode function:

    if( SHORTCODE_UI_DOING_PREVIEW ){
    	$html = 'PLACEHOLDER';
    } else {
    	$html = 'REAL CONTENT';
    }
    return $html;

    But the shortcode renders only the placeholder, both on TinyMCE and the frontend. Am I doing something wrong?

    Thanks for any help!

    https://wordpress.org/plugins/shortcode-ui/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    But the shortcode renders only the placeholder, both on TinyMCE and the frontend. Am I doing something wrong?

    Could be, but it’s hard to say from this code snippet (which seems fine). Can you provide more details on your setup? Are you rendering the editor on the frontend by chance?

    Thread Starter Diego de Oliveira

    (@diegoliv)

    Hi, Daniel, thanks for your response!

    I can’t provide here direct access to the file containing the issue because is a private project for a client. But I can send you a secret gist by email so you can take a look at the entire code if you want. What do you think?

    We’re not rendering the editor at the frontend. At the backend, we created a page and added the shortcode. The placeholder shows up correctly. But at the frontend, instead of rendering the shortcode, it just renders the placeholder.

    I took a look with WP_DEBUG on and we’re getting this error on the frontend page that contains the shortcode:

    Notice:Use of undefined constant SHORTCODE_UI_DOING_PREVIEW - assumed 'SHORTCODE_UI_DOING_PREVIEW' in (...)

    Seems like is related to the issue – if the SHORTCODE_UI_DOING_PREVIEW constant is assumed as defined at the frontend too, it’s logical that it just renders the placeholder, right?

    Thanks for the help!

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Can you instead try:

    if( defined( 'SHORTCODE_UI_DOING_PREVIEW' ) && SHORTCODE_UI_DOING_PREVIEW ){
    	$html = 'PLACEHOLDER';
    } else {
    	$html = 'REAL CONTENT';
    }
    return $html;

    You’re getting the error notice because the constant is only being defined in the admin ajax context.

    Thread Starter Diego de Oliveira

    (@diegoliv)

    Yep, that did the trick. Now it’s working great!

    Thanks, Daniel!

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    +1

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to use SHORTCODE_UI_DOING_PREVIEW?’ is closed to new replies.