wp plugin -3
Paths
Local path:
plugin_dir_path( __FILE__ );
plugin_dir_path( __FILE__ ) .’js/scripts.js’;
URL path:
plugins_url(), Full plugins directory URL, example: http://example.com/wp-content/plugins
includes_url(), http://example.com/wp-includes
content_url(), http://example.com/wp-content
admin_url(), http://example.com/wp-admin
site_url(), http://example.com
home_url(), http://example.com
site_url(), home_url() 区别:
site_url()从wp_options表中,取 siteurl的值,这是WP corefile的url。例如如果wp安装在服务器根目录下 /blog目录,那么返回
http://example.com/wordpress
home_url()从wp_options表中,取home的值,即别人访问时的url,同上的情况,但返回http://example.com
plugins_url( $path, $plugin ) 返回plugin目录中任何文件的full url
$path - (string) (optional) — Path relative to the plugins URL
$plugin - (string) (optional) — Plugin fi le that you want to be relative (that is, pass in
_FILE__ )
例如:
< ?php
echo ‘ < img src=”’ .plugins_url( ‘images/icon.png’ , __FILE__ ). ‘” > ’;
? >
浙公网安备 33010602011771号