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

  • Would you mind to show your code inside get_template_part('page-calcu-info-box'); – Jevuska Apr 1 '16 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? – Mehul Gohil Apr 1 '16 at 6:36
  • your probably doing the add_shortcode too late. – Joel M Feb 23 '18 at 1:26
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, privacy policy and cookie policy

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