如何在 Wordpress 插件中获取 wp_content 目录的路径

问题:

你正在编写一个 wordpress 插件,其中你需要文件系统上 wp-content 目录的路径。

解决方案

使用 WP_CONTENT_DIR 常量。

wp-content-path.php
$path_to_wp_content = WP_CONTENT_DIR; // 例如 "/var/sites/techoverflow.net/wp-content"

注意 WP_CONTENT_DIR 没有尾部斜杠。

像这样使用 WP_CONTENT_DIR . "/"

wp-content-path-trailing-slash.php
$path_to_wp_content = WP_CONTENT_DIR . "/"; // 例如 "/var/sites/techoverflow.net/wp-content/"

获取包含尾部斜杠的 wp_content 路径。


Check out similar posts by category: PHP, Wordpress