Display a text message if the shortcode is not found?Wrap text around shortcodeShortcode does not display paginationShortcode in Text Widget not workingShortcode display outside the divWordPress shortcode display as plain textShortcode - Display inline icon before textCustom Registration username_exists / email_existsShortcode cannot be foundDisplay a text message if the shortcode is found?Display a text message if the field is not found and not if found

A factorization game

What was Bran's plan to kill the Night King?

As a GM, is it bad form to ask for a moment to think when improvising?

How can I get a job without pushing my family's income into a higher tax bracket?

Any examples of liquids volatile at room temp but non-flammable?

Would you use "llamarse" for an animal's name?

Can my 2 children, aged 10 and 12, travel to the USA on expired American Passports?

What to use instead of cling film to wrap pastry

Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?

How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?

How long would it take for people to notice a mass disappearance?

Definition of conditional probability and a problem.

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

Why am I receiving the identity insert error even after explicitly setting IDENTITY_INSERT ON and using a column list?

Manager is threatening to grade me poorly if I don't complete the project

Is there precedence or are there procedures for a US president refusing to concede to an electoral defeat?

What do I do if my advisor made a mistake?

Why did the Apollo 13 crew extend the LM landing gear?

3D Volume in TIKZ

How to create this animation - spline wrap?

How is Per Object Storage Usage Calculated

To kill a cuckoo

Out of scope work duties and resignation

ip rule and route doesn't get respected



Display a text message if the shortcode is not found?


Wrap text around shortcodeShortcode does not display paginationShortcode in Text Widget not workingShortcode display outside the divWordPress shortcode display as plain textShortcode - Display inline icon before textCustom Registration username_exists / email_existsShortcode cannot be foundDisplay a text message if the shortcode is found?Display a text message if the field is not found and not if found






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content()
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) )
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

else
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';

?>
</div>
</article>
</main>
</div>

<?php



I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?




When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve










share|improve this question



















  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41

















3















I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content()
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) )
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

else
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';

?>
</div>
</article>
</main>
</div>

<?php



I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?




When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve










share|improve this question



















  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41













3












3








3








I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content()
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) )
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

else
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';

?>
</div>
</article>
</main>
</div>

<?php



I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?




When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve










share|improve this question
















I'm using the do_shortcode function to add a shortcode in a page. But I would like to check if that shortcode exists before displaying it. If the user has no gallery, I would like to display a message like this: "Sorry no gallery here".



This is my PHP:



<?php
/**
* galeries content
*/

function iconic_galeries_endpoint_content()
echo /* Template Name: Client Area */

get_header();
?>

<div id="primary" class="content-area">
<main id="main" class="site-main">
<article>
<header class="entry-header">
<h1><?php _e( 'Vos galeries photos.', 'my-theme' ); ?></h1>
</header>
<div class="entry-content">
<?php
$current_user = wp_get_current_user();

if ( isset( $current_user->user_email ) )
echo '<p>' . sprintf( __( '%s, this is your galleries', 'my-theme' ), $current_user->display_name ) . ':</p>';
echo do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

else
echo '<p>' . sprintf( __( 'Please <a href="%s">log in</a> to see this page', 'my-theme' ), wp_login_url( get_permalink() ) ) . '.</p>';

?>
</div>
</article>
</main>
</div>

<?php



I haven't found a way to return a message like: "Sorry no gallery here".



Does anyone have a solution?




When client has a gallery to approve
Client has no galerie to approve



And when client has no gallery to approve or he has already approve his photos
Client has a gallery to approve







php plugin-development shortcode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 3 at 22:18









Jack Johansson♦

12k82047




12k82047










asked Mar 30 at 14:36









Nicolas LogerotNicolas Logerot

375




375







  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41












  • 1





    Have you tried the core function shortcode_exists( 'picu_list_collections' )?

    – bueltge
    Mar 31 at 12:41







1




1





Have you tried the core function shortcode_exists( 'picu_list_collections' )?

– bueltge
Mar 31 at 12:41





Have you tried the core function shortcode_exists( 'picu_list_collections' )?

– bueltge
Mar 31 at 12:41










2 Answers
2






active

oldest

votes


















1














do_shortcode() returns content with shortcodes filtered out. We can check the return value and display appropriate message accordingly.



$output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

// the shortcode returns an empty <ul> tag, if there is no gallery
// https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
else echo $output;


I hope this may help!



References:



  1. do_shortcode()

  2. [picu_list_collections]





share|improve this answer

























  • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

    – Nicolas Logerot
    Mar 30 at 15:31











  • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

    – Qaisar Feroz
    Mar 30 at 15:35











  • Thank you very much but I don't know how to find the output of shot code when is no gallery

    – Nicolas Logerot
    Mar 30 at 15:40











  • What is output just after the this is your galleries USER_NAME when page is loaded?

    – Qaisar Feroz
    Mar 30 at 15:53











  • OK, Can you share screenshots in cases of a user has no galleries?

    – Qaisar Feroz
    Mar 30 at 16:12


















1














This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



$gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "110"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333009%2fdisplay-a-text-message-if-the-shortcode-is-not-found%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    do_shortcode() returns content with shortcodes filtered out. We can check the return value and display appropriate message accordingly.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!



    References:



    1. do_shortcode()

    2. [picu_list_collections]





    share|improve this answer

























    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12















    1














    do_shortcode() returns content with shortcodes filtered out. We can check the return value and display appropriate message accordingly.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!



    References:



    1. do_shortcode()

    2. [picu_list_collections]





    share|improve this answer

























    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12













    1












    1








    1







    do_shortcode() returns content with shortcodes filtered out. We can check the return value and display appropriate message accordingly.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!



    References:



    1. do_shortcode()

    2. [picu_list_collections]





    share|improve this answer















    do_shortcode() returns content with shortcodes filtered out. We can check the return value and display appropriate message accordingly.



    $output = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );

    // the shortcode returns an empty <ul> tag, if there is no gallery
    // https://plugins.trac.wordpress.org/browser/picu/trunk/frontend/includes/picu-template-functions.php#L464

    if($output == '<ul class="picu-collection-list"></ul>') echo "Nothing here";
    else echo $output;


    I hope this may help!



    References:



    1. do_shortcode()

    2. [picu_list_collections]






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 30 at 17:13

























    answered Mar 30 at 15:19









    Qaisar FerozQaisar Feroz

    1,7571218




    1,7571218












    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12

















    • Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

      – Nicolas Logerot
      Mar 30 at 15:31











    • @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

      – Qaisar Feroz
      Mar 30 at 15:35











    • Thank you very much but I don't know how to find the output of shot code when is no gallery

      – Nicolas Logerot
      Mar 30 at 15:40











    • What is output just after the this is your galleries USER_NAME when page is loaded?

      – Qaisar Feroz
      Mar 30 at 15:53











    • OK, Can you share screenshots in cases of a user has no galleries?

      – Qaisar Feroz
      Mar 30 at 16:12
















    Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

    – Nicolas Logerot
    Mar 30 at 15:31





    Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot

    – Nicolas Logerot
    Mar 30 at 15:31













    @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

    – Qaisar Feroz
    Mar 30 at 15:35





    @NicolasLogerot , I, in my answer, assumed that if there is no gallery, then the output of your shortcode is an empty string i.e. "" . Can you tell what is the output of shortcode when there is no gallery, or you can replace "" in my code with that output.

    – Qaisar Feroz
    Mar 30 at 15:35













    Thank you very much but I don't know how to find the output of shot code when is no gallery

    – Nicolas Logerot
    Mar 30 at 15:40





    Thank you very much but I don't know how to find the output of shot code when is no gallery

    – Nicolas Logerot
    Mar 30 at 15:40













    What is output just after the this is your galleries USER_NAME when page is loaded?

    – Qaisar Feroz
    Mar 30 at 15:53





    What is output just after the this is your galleries USER_NAME when page is loaded?

    – Qaisar Feroz
    Mar 30 at 15:53













    OK, Can you share screenshots in cases of a user has no galleries?

    – Qaisar Feroz
    Mar 30 at 16:12





    OK, Can you share screenshots in cases of a user has no galleries?

    – Qaisar Feroz
    Mar 30 at 16:12













    1














    This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



    Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



    If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



    $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
    if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





    share|improve this answer



























      1














      This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



      Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



      If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



      $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
      if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





      share|improve this answer

























        1












        1








        1







        This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



        Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



        If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



        $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
        if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;





        share|improve this answer













        This is a curious piece of code. Apparently users can upload a gallery, but your snippet does not show the upload code, so it's impossible to know how it is stored and hence to access to find out if it exists.



        Presumably, the picu_list_collections shortcode knows how to access the gallery, but if there is no gallery you want it to return different output. That would mean modifying the shortcode function itself.



        If you can only modify the current function you must not echo the result, but store it in a variable. Then you can perform a test on it to establish it the returned code reflects the existence of a gallery, for instance by testing it for an img-tag. Like this:



        $gall = do_shortcode( '[picu_list_collections email="' . $current_user->user_email . '"]' );
        if (false=strpos($gall,'<img')) echo 'Sorry no here' else echo $gall;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 30 at 15:04









        cjbjcjbj

        11.2k103067




        11.2k103067



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to WordPress Development Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid …


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f333009%2fdisplay-a-text-message-if-the-shortcode-is-not-found%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bruad Bilen | Luke uk diar | NawigatsjuunCommonskategorii: BruadCommonskategorii: RunstükenWikiquote: Bruad

            Modern approach to radio buttons

            A word for worn pool table felt