在自定义的php文件中调用WordPress内置函数

我正在尝试在自定义文件上使用WordPress功能,但似乎无法正常工作。 该文件位于根目录中。 请帮帮我</ p>
</ div>

展开原文

原文

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

3个回答

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];

    }
?>
duan111112
duan111112 工作!! 谢谢
接近 2 年之前 回复



只需在自定义PHP文件的顶部包含 wp-load.php </ code>文件</ p> \ n

  require_once(“../../../../ wp-load.php”); 
</ code> </ pre>

< strong>注意:</ strong>根据自定义PHP文件添加斜杠和点</ code> ../../../../。</ p>
</ div>

展开原文

原文

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.



您可以通过添加 wp-load.php </ code>文件来访问任何外部文件中的任何wordpress内置函数。 n如果您的文件位于根目录中。 然后,您可以在顶部添加以下代码行。</ p>

  require_once(“wp-load.php”); 
</ code> </ pre>

有关详细信息和示例,您可以访问如何访问外部文件中的Wordpress功能 </ p>
</ div>

展开原文

原文

You can access any wordpress inbuilt function in any external file by adding wp-load.php file. If your file is in the root directory. Then, you can just add following line of code on top.

require_once("wp-load.php");

For more details and example, you can visit How to access Wordpress functions in external file

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐