问题
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]");
?>
回答1:
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.
回答2:
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);
回答3:
Try
echo apply_filters( "the_content","[wpdatatable id=1]");
instead of do_shortcode() and see if that produces the output
来源:https://stackoverflow.com/questions/56560947/how-to-use-wordpress-shortcodes-in-custom-php-file