Display a text message if the shortcode is not found? The Next CEO of Stack Overflow2019 Community Moderator ElectionWrap text around shortcodeShortcode does not display paginationShortcode in Text Widget not workingShortcode display outside the divShortcode for CPT post content in a pageWordPress shortcode display as plain textShortcode - Display inline icon before textPHP Running On CMS Side of WordpressShortcode cannot be foundDisplay shortcode in text field with wordpress settings api
Why does freezing point matter when picking cooler ice packs?
Does int main() need a declaration on C++?
Could a dragon use its wings to swim?
Variance of Monte Carlo integration with importance sampling
Strange use of "whether ... than ..." in official text
How to show a landlord what we have in savings?
Can this transistor (2n2222) take 6V on emitter-base? Am I reading datasheet incorrectly?
Mathematica command that allows it to read my intentions
The sum of any ten consecutive numbers from a fibonacci sequence is divisible by 11
Direct Implications Between USA and UK in Event of No-Deal Brexit
Is it a bad idea to plug the other end of ESD strap to wall ground?
My boss doesn't want me to have a side project
Create custom note boxes
How can I prove that a state of equilibrium is unstable?
How can a day be of 24 hours?
Why did early computer designers eschew integers?
pgfplots: How to draw a tangent graph below two others?
How do I secure a TV wall mount?
Is it reasonable to ask other researchers to send me their previous grant applications?
Why do we say “un seul M” and not “une seule M” even though M is a “consonne”?
Masking layers by a vector polygon layer in QGIS
"Eavesdropping" vs "Listen in on"
Is it possible to create a QR code using text?
Calculating discount not working
Display a text message if the shortcode is not found?
The Next CEO of Stack Overflow2019 Community Moderator ElectionWrap text around shortcodeShortcode does not display paginationShortcode in Text Widget not workingShortcode display outside the divShortcode for CPT post content in a pageWordPress shortcode display as plain textShortcode - Display inline icon before textPHP Running On CMS Side of WordpressShortcode cannot be foundDisplay shortcode in text field with wordpress settings api
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?
php plugin-development shortcode
New contributor
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?
php plugin-development shortcode
New contributor
Have you tried the core functionshortcode_exists( 'picu_list_collections' )
?
– bueltge
yesterday
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?
php plugin-development shortcode
New contributor
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?
php plugin-development shortcode
php plugin-development shortcode
New contributor
New contributor
edited 2 days ago
Kodos Johnson
1053
1053
New contributor
asked 2 days ago
Nicolas LogerotNicolas Logerot
132
132
New contributor
New contributor
Have you tried the core functionshortcode_exists( 'picu_list_collections' )
?
– bueltge
yesterday
add a comment |
Have you tried the core functionshortcode_exists( 'picu_list_collections' )
?
– bueltge
yesterday
Have you tried the core function
shortcode_exists( 'picu_list_collections' )
?– bueltge
yesterday
Have you tried the core function
shortcode_exists( 'picu_list_collections' )
?– bueltge
yesterday
add a comment |
3 Answers
3
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
2 days ago
@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
2 days ago
Thank you very much but I don't know how to find the output of shot code when is no gallery
– Nicolas Logerot
2 days ago
What is output just after the this is your galleries USER_NAME when page is loaded?
– Qaisar Feroz
2 days ago
OK, Can you share screenshots in cases of a user has no galleries?
– Qaisar Feroz
2 days ago
|
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 |
When client has a gallery to approve
And when client has no gallery to approve or he has already approve his photos
New contributor
add a comment |
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
);
);
Nicolas Logerot is a new contributor. Be nice, and check out our Code of Conduct.
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
3 Answers
3
active
oldest
votes
3 Answers
3
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
2 days ago
@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
2 days ago
Thank you very much but I don't know how to find the output of shot code when is no gallery
– Nicolas Logerot
2 days ago
What is output just after the this is your galleries USER_NAME when page is loaded?
– Qaisar Feroz
2 days ago
OK, Can you share screenshots in cases of a user has no galleries?
– Qaisar Feroz
2 days ago
|
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
2 days ago
@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
2 days ago
Thank you very much but I don't know how to find the output of shot code when is no gallery
– Nicolas Logerot
2 days ago
What is output just after the this is your galleries USER_NAME when page is loaded?
– Qaisar Feroz
2 days ago
OK, Can you share screenshots in cases of a user has no galleries?
– Qaisar Feroz
2 days ago
|
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 2 days ago
answered 2 days ago
Qaisar FerozQaisar Feroz
1,249217
1,249217
Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot
– Nicolas Logerot
2 days ago
@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
2 days ago
Thank you very much but I don't know how to find the output of shot code when is no gallery
– Nicolas Logerot
2 days ago
What is output just after the this is your galleries USER_NAME when page is loaded?
– Qaisar Feroz
2 days ago
OK, Can you share screenshots in cases of a user has no galleries?
– Qaisar Feroz
2 days ago
|
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
2 days ago
@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
2 days ago
Thank you very much but I don't know how to find the output of shot code when is no gallery
– Nicolas Logerot
2 days ago
What is output just after the this is your galleries USER_NAME when page is loaded?
– Qaisar Feroz
2 days ago
OK, Can you share screenshots in cases of a user has no galleries?
– Qaisar Feroz
2 days ago
Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot
– Nicolas Logerot
2 days ago
Thanks Qaisar, your code display no message but work when gallery exist, it seems may be a parameter I forgot
– Nicolas Logerot
2 days ago
@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
2 days ago
@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
2 days ago
Thank you very much but I don't know how to find the output of shot code when is no gallery
– Nicolas Logerot
2 days ago
Thank you very much but I don't know how to find the output of shot code when is no gallery
– Nicolas Logerot
2 days ago
What is output just after the this is your galleries USER_NAME when page is loaded?
– Qaisar Feroz
2 days ago
What is output just after the this is your galleries USER_NAME when page is loaded?
– Qaisar Feroz
2 days ago
OK, Can you share screenshots in cases of a user has no galleries?
– Qaisar Feroz
2 days ago
OK, Can you share screenshots in cases of a user has no galleries?
– Qaisar Feroz
2 days ago
|
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 2 days ago
cjbjcjbj
11k102967
11k102967
add a comment |
add a comment |
When client has a gallery to approve
And when client has no gallery to approve or he has already approve his photos
New contributor
add a comment |
When client has a gallery to approve
And when client has no gallery to approve or he has already approve his photos
New contributor
add a comment |
When client has a gallery to approve
And when client has no gallery to approve or he has already approve his photos
New contributor
When client has a gallery to approve
And when client has no gallery to approve or he has already approve his photos
New contributor
New contributor
answered 2 days ago
Nicolas LogerotNicolas Logerot
132
132
New contributor
New contributor
add a comment |
add a comment |
Nicolas Logerot is a new contributor. Be nice, and check out our Code of Conduct.
Nicolas Logerot is a new contributor. Be nice, and check out our Code of Conduct.
Nicolas Logerot is a new contributor. Be nice, and check out our Code of Conduct.
Nicolas Logerot is a new contributor. Be nice, and check out our Code of Conduct.
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
Have you tried the core function
shortcode_exists( 'picu_list_collections' )
?– bueltge
yesterday