ABSPATH or __FILE__?

前端 未结 4 1462
长情又很酷
长情又很酷 2020-12-24 14:42

Can someone tell me if either of these two methods has an advantage over the other and why?

$mydir = ABSPATH.\'/wp-content/themes/mytheme/images\';

4条回答
  •  悲哀的现实
    2020-12-24 14:59

    • The path to the "wp-content" directory and its subdirectories can be different in a particular WordPress installation. Also, using the WordPress internal constants (such as ABSPATH) is not recommended. See the Determining Plugin and Content Directories WordPress Codex article.
    • Since PHP 4.0.2, symlinks are being resolved for the __FILE__ and __DIR__ magic constants, so take that into account.

      Bottom line: To determine the absolute path to a theme directory, I would suggest to use the get_template_directory() function which also applies filters and internally combines get_theme_root() and get_template().

提交回复
热议问题