Shortcode Appearing Twice In Top Bar

Hello,

I am using the following code in my functions file to get shortcodes to appear in my topbar:

add_filter( ‘x_option_x_topbar_content’, ‘topbar_content_filter’ );

However an unintended consequence of this is that the shortcode appears twice.

This does not happen when it is elsewhere on the website.

Does anyone have any solutions?

Thanks!

Hi Chiara,

Thanks for writing in! You have not posted the full code, so I’m not sure how your code executes. Please remove your existing code and try adding the following code into your child theme’s functions.php file. If you don’t have a child theme, please setup it accordingly by following this guide (https://theme.co/apex/forum/t/setup-how-to-setup-child-themes/57).

// Enable Shortcode feature in Topbar
function x_enable_topbar_shortcode( $content ) {
  return is_admin() ? $content : do_shortcode( $content );
}
add_filter( 'x_option_x_topbar_content', 'x_enable_topbar_shortcode', 20 );

Let us know how it goes.
Thanks!

Dear @mldarshana,

Thank you for getting back to me. I have removed the existing code and replaced it with the code you sent me. The problem still exists. Please might you take a look?

The domain of my website is: www.smokingjacket.london

Thank you!

Hi Chiara,

I tried and yes, seems to be not working but, it’s due to missing condition. Please change the above code to this

function x_enable_topbar_shortcode( $content ) {
  return ! is_admin() ? $content : do_shortcode( $content );
}
add_filter( 'x_option_x_topbar_content', 'x_enable_topbar_shortcode', 20 );

Thanks!

Dear @Rad,

Thanks for getting back to me, I updated the code with the code you sent me but now the short code is just displaying text rather than one or two versions!

Thanks!

Hi Chiara,

Please revert back to the code provided by Darshana. The duplicate problem is not happening on our dev site, so it could be something on your setup is doing that, please do testing for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.

Also, clear all your caching features/plugin (if any)

Let us know how it goes,
Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.