this has been discussed before however it's not working for me. As the shortcode seems to be a mix of regular and open-close shortcode. Or a combination of nested shortcodes.
// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode( '' );
// In case there is opening and closing shortcode.
echo do_shortcode( '[iscorrect]' . $text_to_be_wrapped_in_shortcode . '[/iscorrect]' );
This is the shortcode I would like to display in my php template
[mk_page_section bg_stretch="true" full_width="true" padding_top="0" padding_bottom="0" sidebar="sidebar-1"][vc_column][mk_header hover_styles="5" logo="false"][/vc_column][/mk_page_section]
What I am trying to achieve is display my main navigation on a webinar page that doesn't use my themes header or footer.
Is mit possible to use it like this?
<?php echo do_shortcode('[mk_page_section bg_stretch="true" full_width="true" padding_top="0" padding_bottom="0" sidebar="sidebar-1"][vc_column][mk_header hover_styles="5" logo="false"][/vc_column][/mk_page_section]'); ?>
Or must it be a combination? totally lost here...
Why is the do_shortcode not working?
Related
I'm working on a page template and I'm having trouble working out how I can echo a string of php. Basically I have set up a custom field inside Wordpress for the page called Slider Code, and it asks the user to paste in the slider code given to them so that the appropriate slider is displayed on the page. The slider code given looks like this: [soliloquy id="82"]
The custom field plugin gives me this code to use in the template to echo out whatever is in that field, which looks like this: <?php echo CFS()->get('slider_code'); ?>
In WordPress there is a php function called do_shortcode which enables me to use that code, so it would look like this: <?php do_shortcode('[soliloquy id="82"]'); ?> and the slider would be displayed. So is there any way I can merge that <?php echo CFS()->get('slider_code'); ?> string with the do_Shortcode string? If not, does anyone have any alternative solutions to this issue? I can only think of having to make separate page templates for each individual slider.
EDIT: I have just discovered that the do_shortcode function does not actually work at all with the soliloquy shortcode. It does give me the option of using this code: if ( function_exists( 'soliloquy' ) ) { soliloquy( '82' ); }. However, when I paste this code into the custom field as is, the <?php echo CFS()->get('slider_code'); ?> tag just echos out that text. If I wrap the code in the custom field in <?php and ?> it just comments the code out inside my inspector. How do I get around this?
Check this out.
$slider = CFS()->get('slider_code');
call_user_func('do_shortcode', $slider);
I don't understand why you can't just run do_shortcode(CFS()->get('slider_code')).
Ok. Then try this one. Paste this code in the template file.
<?php
if ( function_exists( 'soliloquy' ) ) {
soliloquy( CFS()->get('slider_code') );
}
?>
And for slider_code input just enter '82'. If you are unable to see what is the template file you have to paste the above given code, then try to see WordPress template conventions.
I'm currently learning wordpress theme development and for better understanding I have downloaded couple of wordpress theme and seeing their code.
But a line of code I can't understand. here it is-->
<?php echo do_shortcode(sq_option( 'footer_text ' ' ')); ?>
maybe its for footer but how this works and how i can use this function when I will create my own.
do_shortcode is a function you have to use if you want to execute a shortcode inside a custom theme template page see more info on the function here: https://developer.wordpress.org/reference/functions/do_shortcode/
Generally do_shortcode(); is use to get data from shortcode or its attribute to your PHP code or to filter any shortcode returning data. Shortcode can be provided by any plugin.
Not sure about it but in your theme's code sq_option("footer_text"); could be a function which is filtering some text from footer.
The code could be as:
<?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>
Reference Link
do_shortcode () is usefull function-> for excute shortcode in template file
On a php page in wordpress, I have a shortcode for an accordion, that consists of the following, and works perfectly:
<?php echo do_shortcode('[su_accordion]
[su_spoiler title="Feature Locations" style="fancy"] CONTENT GOES HERE
[/su_spoiler]
[/su_accordion]'); ?>
Within the accordion, I want to display an interactive map, which can be displayed using either a shortcode, or PHP. Both options are:
[show-map id='1'], or
<?php build_i_world_map(1); ?>
When I insert either of these into the accordion shortcode, the map does not display. However, outside of the accordion, the second option above (with php) displays successfully.
What am I missing in terms of including this in the shortcode for the accordion?
In your example your outer section should be like
<?php echo do_shortcode('[su_accordion]
[su_spoiler title="Feature Locations" style="fancy"]'. build_i_world_map(1) .'
[/su_spoiler]
[/su_accordion]'); ?>
In wordpress you should call do_shortcode() for shortcode calls.
<?php echo do_shortcode("[show-map id='1']"); ?>
do_shortcode() reference
this is an effective way to include a concatenating inside a shortcode function
<?php echo do_shortcode('[download url='.$next_attachment_url.']'); ?>
I'm all tied up in knots trying to echo shortcodes within shortcodes and I really need your help please!
Here's the code:
function custom_listify_single_job_listing_actions_after() {
global $post;
$url = get_post_meta( $post->ID, 'your_custom_meta_key', true );
echo 'Contact me';
echo '<div id="my-popup" class="popup"><?php echo do_shortcode('[groups_member group="Active Employer"]<?php echo do_shortcode('[widget id="jmfe_widget-7"]');?>[/groups_member]');?></div>';
}
add_filter( 'listify_single_job_listing_actions_after', 'custom_listify_single_job_listing_actions_after' );
The function adds a button to my site which opens a modal popup when clicked. I'm tying to display content within that popup that is restricted based on membership. That part uses the groups_member shortcode. Then, I'm trying to display content within the groups_member shortcode that belongs to a widget.
Each of the shortcodes works individually - the button, the popup, the restricted content and the widget shortcode - problem is that it doesn't work when I try to put it all together. I've wondered about creating a shortcode that contains the other shortcodes and then somehow inserting that into the popup function, but I'm rubbish at this stuff as it turns out! Can you help please?
I'm not to sure what you are after but echo with php, using string operators would give something like this, which is untested and may be missing a dot or a ' somewhere
echo '<div id="my-popup" class="popup">'.do_shortcode('[groups_member group="Active Employer"]'.do_shortcode('[widget id="jmfe_widget-7"]').'[/groups_member]').'</div>';
I'm using the wordpress php widget but I am unable to process Wordpress shortcode - the php just renders the shortcode instead of processing it. HEre is what I did
Added filters to my active theme function.php file
add_filter('widget_text', 'shortcode_unautop');
add_filter('widget_text', 'do_shortcode');
// Allow shortcodes in php code widget
add_filter('widget_execphp', 'shortcode_unautop');
add_filter('widget_execphp', 'do_shortcode');
Added the following to the php widget
<?php
$id = get_the_ID();
$amazon_product_asin_value = get_post_meta($id, 'amazon_product_asin', true);
echo do_shortcode('<div> [amazon asin=' . $amazon_product_asin_value . '&template=buynowamazon_widget&chan=default] </div>');
?>
I also tried without do_shortcode and same result.
2 properly outputs the shortcode of
[amazon asin=B008I20FT8&template=buynowamazon_widget&chan=default]
which works fine if I just enter this in the standard text widget
I'm using the Amazon Link plugin which generates the shortcodes
Any ideas?
The asin parameter value might be confusing the shortcode processor; try putting quotes around it.
echo do_shortcode('<div> [amazon asin="' . $amazon_product_asin_value . '&template=buynowamazon_widget&chan=default"] </div>');
Alternatively, does the shortcode accept each argument to that parameter as a separate parameter?
echo do_shortcode('<div> [amazon asin="' . $amazon_product_asin_value . '" template="buynowamazon_widget" chan="default"] </div>');
Edit: Looking at the plugin's code, I don't think you need these lines:
add_filter('widget_execphp', 'shortcode_unautop');
add_filter('widget_execphp', 'do_shortcode');
They will try to process the shortcode, before the PHP is executed, and thus you won't get the shortcode correctly processed. Comment them out and see what the plugin does now.