【问题标题】:get_template_directory_uri() suddenly started returning the wrong valueget_template_directory_uri() 突然开始返回错误的值
【发布时间】:2020-01-26 22:11:28
【问题描述】:

在我的网站上,函数get_template_directory_uri() 在使用我的子主题时开始返回完全错误的值。就在刚才,这一切都在工作,儿童主题和一切。然后突然间它开始返回http://example.com/~villageofmanteno/vmanteno-child,而它应该是http://example.com/~villageofmanteno/yootheme-child。现在整个站点都损坏了,所有脚本 URL 都返回 404。站点根目录位于 /~villageofmanteno。

这是现在真正奇怪的部分,我得到的 URL 的最后一段,vmanteno-child 似乎不是来自任何地方。我从来没有在任何地方输入过,没有文件或主题以vmanteno 命名。 vmanteno 这个词从未出现在我的代码中。所以我不知道这可能是从哪里来的。

我什至尝试删除我的子主题,重新创建它,然后复制我的旧文件,但它仍然损坏。当我关闭子主题时,一切都很好。

子主题文件夹名为yootheme-child。

现在我的子主题中唯一的模板文件是page-meetings.php,但是这个问题会影响整个网站的每个页面,所以这与它没有任何关系。

这是我的style.css:

/*
Theme Name: YOOtheme Child
Theme URI: https://yootheme.com
Template: yootheme
Author: YOOtheme
Author URI: https://yootheme.com
Description: A powerful, flexible and elegant website builder that allows you to create complex pages within minutes and customize every aspect of the theme.
Version: 1.21.6.1569423942
Updated: 2019-09-25 15:05:42
*/

还有我的functions.php:

<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
    function chld_thm_cfg_locale_css( $uri ){
        if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
            $uri = get_template_directory_uri() . '/rtl.css';
        return $uri;
    }
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );

// END ENQUEUE PARENT ACTION

我还要提一下,WordPress 地址和站点地址都设置为正确的值http://example.com/~villageofmanteno。

编辑:get_template_directory_uri() 和 get_stylesheet_directory_uri() 返回相同的内容。

【问题讨论】:

    标签: wordpress wordpress-theming child-theming


    【解决方案1】:

    我已经放弃解决这个问题了。删除旧的子主题并创建一个具有相同名称的新主题会导致相同的问题,但是创建一个具有不同名称的新子主题以某种方式起作用。将主题名称更改回 yotheme-child 会再次破坏它。不知道为什么。

    【讨论】:

      【解决方案2】:

      请注意,get_template_directory_uri() 将返回父主题的 URL,如果您想要子主题的 URL,则应使用 get_stylesheet_directory_uri()。

      请注意,这两个函数还具有允许更改 URL 的内部过滤器,例如 get_template_directory_uri() 有一个名为 template_directory_uri 的过滤器,因此可能是第 3 方主题或插件已更改它。

      【讨论】:

      • 嗯,它返回的 URL 也不是我的父主题文件夹,如果是这样的话,它应该是 yootheme。它根本不对应任何东西。此外,WordPress 本身没有为其脚本和 CSS 导入生成正确的 URL,导致所有内容为 404。没有安装其他主题。
      • get_template_directory_uri() 和 get_stylesheet_directory_uri() 实际上返回的是相同的东西。我也没有换过任何插件,也很少。
      • 但是如果 WordPress 本身不能正确生成正确的 URL,那么问题听起来不仅仅是主题,还有一些代码在 WordPress 上进行更改。
      猜你喜欢
      • 1970-01-01
      • 2022-07-28
      • 2011-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      • 2019-04-02
      相关资源
      最近更新 更多