Archived topic
Adding Conditional code in Hooks
23 replies · Started by GeneratePressUser on April 26, 2020
Hello,
Yes, is it possible for you to email me, I will share with u account details so that u get better idea of it and will share there screenshot for the same things to better understand, I can’t share here in public.
You can send information and URLs via the Account Issue form here:
Hello David,
Done, all things sent via that form :)
Hi there,
It's pretty difficult to debug something like this without digging deep into the code of the shortcodes, which isn't really something we can do.
We can help debug though. For example, is it any two shortcodes, or only a specific pair of shortcodes?
You could try doing something like this:
<?php
if ( is_single( 'post-id' ) ) {
echo do_shortcode( '[Custom shortcode 1]' );
echo do_shortcode( '[Custom shortcode 2]' );
}
?>
Then un-check the "Execute Shortcodes" option.
Hello Tom,
Yes, I can understand, even I don't want to dig deep into debugging code of shortcodes nor I want you guys to do that.
I will test the code which you gave and let you know how it goes.
Hello Tom,
Brilliant! That solved it lol.
Any idea what could have caused that?
Btw in same format:
<?php
if ( is_single( 'post-id' ) ) {
echo do_shortcode( '[Custom shortcode 1]' );
echo do_shortcode( '[Custom shortcode 2]' );
}
?>
Can you pls give me code to write custom html code in it? like right now it's echo do_shortcode so what to write to execute something other than shortcode?
When you execute shortcodes in the hook, it wraps the entire content in a do_shortcode() function. Perhaps it didn't like executing multiple shortcodes at once.
You can add HTML like this:
<?php
if ( is_single( 'post-id' ) ) {
echo '<div class="first-shortcode">';
echo do_shortcode( '[Custom shortcode 1]' );
echo '</div>';
echo '<div class="second-shortcode">';
echo do_shortcode( '[Custom shortcode 2]' );
echo '</div>';
}
?>
Got it, thanks a lot :)
You're welcome :)