Display a text message if the shortcode is not found? The 2019 Stack Overflow Developer Survey Results Are In2019 Community Moderator Election Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Moderator Election Q&A - QuestionnaireWrap 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
Can we generate random numbers using irrational numbers like π and e?
Why are PDP-7-style microprogrammed instructions out of vogue?
Why can I use a list index as an indexing variable in a for loop?
Is it ok to offer lower paid work as a trial period before negotiating for a full-time job?
Circular reasoning in L'Hopital's rule
Would an alien lifeform be able to achieve space travel if lacking in vision?
can infinity be divided by anything?
Do working physicists consider Newtonian mechanics to be "falsified"?
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
Can a flute soloist sit?
Solving overdetermined system by QR decomposition
Word to describe a time interval
How to handle characters who are more educated than the author?
Is every episode of "Where are my Pants?" identical?
Categorical vs continuous feature selection/engineering
Was credit for the black hole image misappropriated?
Word for: a synonym with a positive connotation?
How to substitute curly brackets with round brackets in a grid of list
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
Grounding Vcc and Vee?
Is Cinnamon a desktop environment or a window manager? (Or both?)
Using `min_active_rowversion` for global temporary tables
Do ℕ, mathbbN, BbbN, symbbN effectively differ, and is there a "canonical" specification of the naturals?
Why can't wing-mounted spoilers be used to steepen approaches?
Display a text message if the shortcode is not found?
The 2019 Stack Overflow Developer Survey Results Are In2019 Community Moderator Election
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Moderator Election Q&A - QuestionnaireWrap 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;
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
And when client has no gallery to approve or he has already approve his photos
php plugin-development shortcode
add a comment |
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
And when client has no gallery to approve or he has already approve his photos
php plugin-development shortcode
1
Have you tried the core functionshortcode_exists( 'picu_list_collections' )
?
– bueltge
Mar 31 at 12:41
add a comment |
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
And when client has no gallery to approve or he has already approve his photos
php plugin-development shortcode
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
And when client has no gallery to approve or he has already approve his photos
php plugin-development shortcode
php plugin-development shortcode
edited Apr 3 at 22:18
Jack Johansson♦
11.9k81945
11.9k81945
asked Mar 30 at 14:36
Nicolas LogerotNicolas Logerot
375
375
1
Have you tried the core functionshortcode_exists( 'picu_list_collections' )
?
– bueltge
Mar 31 at 12:41
add a comment |
1
Have you tried the core functionshortcode_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
add a comment |
2 Answers
2
active
oldest
votes
do_shortcode()
returns content with shortcodes filtered out. Assuming that your shortcode returns ""
if user has no gallery, then you can check the return value and display your message.
$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!
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
|
show 5 more comments
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
do_shortcode()
returns content with shortcodes filtered out. Assuming that your shortcode returns ""
if user has no gallery, then you can check the return value and display your message.
$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!
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
|
show 5 more comments
do_shortcode()
returns content with shortcodes filtered out. Assuming that your shortcode returns ""
if user has no gallery, then you can check the return value and display your message.
$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!
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
|
show 5 more comments
do_shortcode()
returns content with shortcodes filtered out. Assuming that your shortcode returns ""
if user has no gallery, then you can check the return value and display your message.
$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!
do_shortcode()
returns content with shortcodes filtered out. Assuming that your shortcode returns ""
if user has no gallery, then you can check the return value and display your message.
$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!
edited Mar 30 at 16:24
answered Mar 30 at 15:19
Qaisar FerozQaisar Feroz
1,5011217
1,5011217
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
|
show 5 more comments
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
|
show 5 more comments
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;
add a comment |
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;
add a comment |
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;
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;
answered Mar 30 at 15:04
cjbjcjbj
11.1k103067
11.1k103067
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Have you tried the core function
shortcode_exists( 'picu_list_collections' )
?– bueltge
Mar 31 at 12:41