Products
GG网络技术分享 2025-03-18 16:12 2
I am trying to use WordPress functions on a custom file but doesn\'t seems to be working. The file is placed in root directory. Please help me out
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我正在尝试在自定义文件上使用WordPress功能,但似乎无法正常工作。 该文件位于根目录中。 请帮帮我</ p>
</ div>
In any custom page you can call below three lines to pull up WordPress stack and then use any WordPress functionality
<?//Imp to include
include(\'wp-load.php\');
define(\'WP_USE_THEMES\', false);
require(\'wp-blog-header.php\');
// check is user is logged - if yes then print its role
if(is_user_logged_in() ) {
$user = wp_get_current_user();
$role = ( array ) $user->roles;
echo \\\"role is \\\".$role[0];
}
?>
###
Just include wp-load.php
file at the top of the custom PHP file
require_once(\\\"../../../../wp-load.php\\\");
Note: add slashes and dots
../../../../ as per the custom PHP file exists.
###
You can access any wordpress inbuilt function in any external file by adding wp-load.php
file.
require_once(\\\"wp-load.php\\\");
For more details and example, you can visit How to access Wordpress functions in external file
Demand feedback