Kunal Patel
Kunal Patel

Reputation: 13

How to use wordpress shortcodes in custom php file?

I want to display wpdatatables(plugin) in my custom PHP file so I wanted to use "do_shortcode()" function but nothing works it just shows white screen.

my php file code:

<?php
    $path = $_SERVER['DOCUMENT_ROOT'];
    include_once $path . '/wp-config.php';
    include_once $path . '/wp-load.php';
    include_once $path . '/wp-includes/wp-db.php';
    include_once $path . '/wp-includes/pluggable.php';
    define('WP_USE_THEMES', false);
    echo do_shortcode("[wpdatatable id=1]");
 ?>

Upvotes: 1

Views: 2605

Answers (3)

Rajesh Kakkad
Rajesh Kakkad

Reputation: 186

Try

echo apply_filters( "the_content","[wpdatatable id=1]");

instead of do_shortcode() and see if that produces the output

Upvotes: 0

GMarco24
GMarco24

Reputation: 418

I think somehow you are not hitting correct page. Can you try to just echo something in that code? Even if shortcode isn't working you should get echo of [wpdatatable id=1] on screen.

If echo works, that probably means your shortcode isn't returning anything, so check that part also. E.g. create a new page from admin panel and try the shortcode.

Upvotes: 1

Pavan Yogi
Pavan Yogi

Reputation: 178

Turn on the debug mode, you will get a reason for the white screen. For example, put this code in your wp-config.php and reload the page.

define('WP_DEBUG', true);

Upvotes: 0

Related Questions