John Davidson

php - Why doesn't the shortcode appear inside the elementor html widget?

0 comments
Message:


I have some custom html, css and js inside elementor's html widget. At some point I had to insert a div tag with a shortcode made by me inside. The shortcode displays fine in elementor's shortcode widget, but does not display inside elementor's html widget. Why does this happen ?


This is the shortcode I have in functions.php - It works everywhere except in elementor's html widget


// Shortcode current username
function display_current_username () {
$user = wp_get_current_user();
$name = $user->user_firstname;

// If the $name var is empty, return the user_firstname property.
if ( $name === '' ) :
return $user->display_name;
endif;

return $name;
}
add_shortcode('display_name', 'display_current_username');


My Answer:
The reason why the shortcode does not appear inside the Elementor HTML widget is because the HTML widget does not parse shortcodes by default.

To make the shortcode work inside the Elementor HTML widget, you can use the do_shortcode() function in your HTML code.

Here's an example of how you can use the do_shortcode() function in your Elementor HTML widget:

html

Hello, [display_name]!





By using the do_shortcode() function, the shortcode [display_name] will be parsed and replaced with the output of the display_current_username() function.

So, make sure to use the do_shortcode() function in your HTML code inside the Elementor HTML widget to make the shortcode work properly.

Rate this post

3 of 5 based on 6491 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us