1

I have a custom templates and I used custom shortcodes to displayed it in the page. But the shortcode is not working, its displayed as plain text only. I already deactivate and reactive the plugin but still have same issue.

I have a custom templates and I used custom shortcodes to displayed it in the page. But the shortcode is not working, its displayed as plain text only. I already deactivate and reactive the plugin but still have same issue.

I'm using this [info_box_calculator] but it display as plain text or sometimes it gives me a blank page

How to fix this?

function info_box_calculator(){
ob_start();
get_template_part('page-calcu-info-box');
return ob_get_clean();
}
add_shortcode('info_box_calculator', 'info_box_calculator');

Link

3
  • Would you mind to show your code inside get_template_part('page-calcu-info-box');
    – Jevuska
    Commented Apr 1, 2016 at 2:21
  • Please mention in which file you have placed the code for shortcode? functions.php of theme or any plugin's file? or any other file? Commented Apr 1, 2016 at 6:36
  • your probably doing the add_shortcode too late.
    – Joel M
    Commented Feb 23, 2018 at 1:26

1 Answer 1

2

First of all as far as I know that you can't call get_template_part() from your plugin.It's a Theme only function . Try to keep your calculator code's in a php file inside your plugin's directory and include it like bellow:

function info_box_calculator_core(){
    include( plugin_dir_path( __FILE__ ) . 'mydir/calculator.php');
    //replace 'mydir/calculator.php' with your file name 
}
add_shortcode('info_box_calculator', 'info_box_calculator_core');

Let me know if it works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.