0

我最近使用 elementor 页面构建器为 OceanWP 创建了一个子主题。我已通过 Filezilla FTP 将文件夹上传到父文件夹旁边的主题文件夹中。在清除 WP Rocket 和 Cloudflare CDN 上的缓存后,我创建了 style.css 和 functions.php 并将适当的代码添加到站点的每个页面和所有页面中。

然后我去添加一个footer.php文件(因为我需要在附属链接标签之前的文件中添加一些额外的代码</head>),这就是我感到困惑的地方。

我应该从父母那里复制代码footer.php并将其插入孩子吗?(我这样做了,我的边距变得一团糟,css 样式变得疯狂)

在我添加我需要的代码之前,它应该留空吗?(我这样做了,我的页脚消失了,菜单无法正常工作?!)

两者都不是,我是否需要在子主题中添加某种类型action or enqueue scriptfunctions.php允许页脚正确显示?

我正在这样做,所以当更新主题时,这些代码片段不会完全从我的服务器和站点中删除。

我什至需要这样做吗,我应该将它添加到父 footer.php 文件中吗?

我对编码非常陌生,只知道少量的 HTML、CSS,并且刚刚开始学习 PHP。

这是我的子主题 function.php 文件中的代码

/**
 * Child theme functions
 *
 * When using a child theme (see http://codex.wordpress.org/Theme_Development
 * and http://codex.wordpress.org/Child_Themes), you can override certain
 * functions (those wrapped in a function_exists() call) by defining them first
 * in your child theme's functions.php file. The child theme's functions.php
 * file is included before the parent theme's file, so the child theme
 * functions would be used.
 *
 * Text Domain: oceanwp
 * @link http://codex.wordpress.org/Plugin_API
 *
 */

/**
 * Load the parent style.css file
 *
 * @link http://codex.wordpress.org/Child_Themes
 */
function oceanwp_child_enqueue_parent_style() {
    // Dynamically get version number of the parent stylesheet (lets browsers re-cache your stylesheet when you update your theme)
    $theme   = wp_get_theme( 'OceanWP' );
    $version = $theme->get( 'Version' );
    // Load the stylesheet
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'oceanwp-style' ), $version );
    
}
add_action( 'wp_enqueue_scripts', 'oceanwp_child_enqueue_parent_style' );
4

1 回答 1

0

你写道:“然后我去添加一个 footer.php 文件(因为我需要在文件中添加一些额外的代码,就在附属链接的 head 标记之前),这就是我感到困惑的地方。”

“就在标签头之前”与footer.php无关

通常,

文件 footer.php 与“就在标签正文之前”有关

文件 header.php 与“就在标签头之前”有关

我说通常是因为在某些主题中 header.php 和 footer.php 会调用其他文件或函数。

所以,首先,确保你没有混淆 header.php 和 footer.php

如果您的目标是在标签头之前编写额外的代码,请复制 header.php 并将其放入您的子主题中。然后修改那个文件。

于 2020-08-11T17:49:01.850 回答