【发布时间】:2020-04-10 20:49:27
【问题描述】:
我是 Wordpress 方面的新手。 我刚刚创建了一个子主题,需要您在 php 编码和 functions.php 相关方面的帮助。
我已经从父主题 (assets/inc/header-related.php) 复制了它,并将其放入子主题文件夹中,保持文件夹的结构。
在 header-related.php 中有一个我要编辑的徽标部分。这是下面的代码
* Logo */
function thb_logo( $section = false ) {
$logo = ot_get_option( 'logo', Thb_Theme_Admin::$thb_theme_directory_uri. 'assets/img/logo.png' );
$loading = 'auto';
$classes[] = 'logo-holder';
if ($section == 'fixed-logo') {
$logo = ot_get_option( 'logo_fixed', $logo );
$classes[] = 'fixed-logo-holder';
$loading = 'lazy';
} elseif ($section == 'mobile-logo') {
$logo = ot_get_option( 'mobile_logo', $logo );
$classes[] = 'mobile-logo-holder';
$loading = 'lazy';
} elseif ($section == 'logo_mobilemenu') {
$logo = ot_get_option( 'logo_mobilemenu', $logo );
$classes[] = 'mobilemenu-logo-holder';
$loading = 'lazy';
}
?>
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
<a href="<?php echo esc_url( home_url('/') ); ?>" class="logolink" title="<?php bloginfo('name'); ?>">
<img src="<?php echo esc_url( $logo ); ?>" loading="<?php echo esc_attr( $loading ); ?>" class="logoimg logo-dark" alt="<?php bloginfo('name'); ?>" />
</a>
</div>
<?php
}
add_action( 'thb_logo', 'thb_logo', 2, 1 );
我想更换主题目录
$logo = ot_get_option( 'logo', Thb_Theme_Admin::$thb_theme_directory_uri. 'assets/img/logo.png'
这样它就从子主题而不是父主题中指向 assets/img/logo.png,就像它现在正在做的那样。我也将其更改为 logo.svg 并将 svg 添加到文件夹中,但它似乎再次将其从父目录中取出。
现在,我需要做什么才能使其指向子主题文件夹?我应该将它添加/排队到我的子主题功能中吗?如果是的话,你知道怎么做吗?
我不确定是否应该在我的子主题中上传文件夹结构,或者只是在 functions.php 中添加代码
如果有人可以指导我,我将不胜感激,如果听起来令人困惑,我会道歉,但希望我的问题可以理解。谢谢!
P.S 这是我的functions.php 的样子:
<?php /*
This file is part of a child theme called rekuin2020.
Functions in this file will be loaded before the parent theme's functions.
For more information, please read
https://developer.wordpress.org/themes/advanced-topics/child-themes/
*/
// this code loads the parent's stylesheet (leave it in place unless you know what you're doing)
function your_theme_enqueue_styles() {
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style,
get_template_directory_uri() . '/style.css');
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array($parent_style),
wp_get_theme()->get('Version')
);
}
add_action('wp_enqueue_scripts', 'your_theme_enqueue_styles');
/* Add your own functions below this line.
======================================== */
【问题讨论】:
-
这是我的函数的样子: