可以使用在需要主题目录URI的场合,例如图片 <img src="<?php echo get_stylesheet_directory_uri() ?>/images/aternus.png" alt="" title="" width="" height="" /> get_template_directory_uri() 如果当前启用的主题是一个child theme,该函数返回parent
get_template_directory_uri() 如果当前启用的主题是一个 child theme,该函数返回 parent theme 的主题目录URI,用法与 get_stylesheet_directory_uri() 类似。 get_template_directory() 如果当前启用的主题是一个child theme,该函数返回 parent theme 的主题目录的服务器绝对路径,用法与 get_stylesheet_directory() ...
问Wordpress用完全限定的http://localhost/代替relative来解析get_template_directory_uri()ENhttp协议是前...
(将代码添加到您的子主题或自定义插件的 functions.php 中) // load the JS filefunctionwdm_mm_toggle_scripts(){wp_enqueue_script('wdm-mm-toggle',get_stylesheet_directory_uri().'/js/mobile-menu-toggle.js',array('jquery'));}add_action('wp_enqueue_scripts','wdm_mm_toggle_scripts'); 一旦...
echo get_stylesheet_directory_uri(); //输出:http://www.uedsc.com/wp-content/themes/twentyeleven 可以使用在需要主题目录URI的场合,例如图片 get_template_directory_uri() 如果当前启用的主题是一个child theme,该函数返回parent theme的主题目录URI,用法与get_stylesheet_directory_uri()类似。
$op_get_stylesheet_directory_uri = get_stylesheet_directory_uri(); /** //获取当前启用的主题目录的URI * 输出:http://www.solagirl.net/wp-content/themes/twentyeleven * 可以使用在需要主题目录URI的场合,例如图片 * <img src="<?php echo get_stylesheet_directory_uri() ?>/images/aternus....
'stylesheet_url'- 显示当前使用的主题的 CSS文件(通常为 style.css)路径。可以考虑使用 get_stylesheet_uri() 代替。 'stylesheet_directory'- 显示当前使用的主题的样式表路径。可以考虑使用 get_stylesheet_directory_uri() 代替。 'template_url'/'template_directory'- 当前主题的 URL 路径 。在子主题中, get...
get_stylesheet_directory_uri() . '/style.css', array(), '1.0' ); // Load the webfont. wp_enqueue_style( 'literata', 'https://fonts.googleapis.com/css2?family=Literata&display=swap', array(), '1.0' ); } add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_assets' ); 要本地...
插件使用 plugins_url() 函数生成脚本路径,主题使用 get_template_directory_uri() (父主题)或 get_stylesheet_directory_uri() (子主题)生成脚本路径 按需加载脚本文件(下文将详细说明) 正确加载脚本的基本方式 如果前面的4点还不是很了解,建议先看下我们之前的教程: 正确加载 CSS 到 WordPress 正确加载 Javascrip...
但是,如果您在主题中使用 enqueue 脚本功能,则只需使用即可get_template_directory_uri()。如果您正在使用子主题,请使用get_stylesheet_directory_uri(). 下面是一个示例代码: <?php function wpb_adding_scripts() {wp_register_script('my_amazing_script', get_template_directory_uri() . 'cdn.wpbeginner.com...