Daunkesum
Daunkesum

Reputation: 1

how to change parent theme directory url in child theme pointing to child theme directory

I'm new to the WordPress side of things. I just created a child theme and need your assistance with PHP coding and functions.php related.

I have copied this from parent theme (assets/inc/header-related.php) and put it to child theme folder, keeping the structure of the folders.

Inside the header-related.php there is a section for the logo that I want to edit. Here is the code below

/* 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';
    }
}

add_action( 'thb_logo', 'thb_logo', 2, 1 );
<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>

I would like to change the theme directory

$logo = ot_get_option( 'logo', Thb_Theme_Admin::$thb_theme_directory_uri. 'assets/img/logo.png' 

So that it points the assets/img/logo.png from the child theme and not the parent theme as it is doing right now. Also, I've changed it to logo.svg and added the SVG in the folder, but again it seems to be taking it from the parent directory.

Now, what do I need to do in order for this to point to child theme folders? Should I add/enqueue it into my child theme functions? If so, would you know how?

I'm not sure whether I should have uploaded the folder structure inside my child theme or just add a code inside the functions.php

I would appreciate it if someone can guide me and apologies if it might sound confusing but hope my question is understandable.

P.S this is what my functions.php looks like:

/*
  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.
    ======================================== */ 

Upvotes: 0

Views: 484

Answers (1)

Stefan
Stefan

Reputation: 55

$logo = ot_get_option( 'logo', Thb_Theme_Admin::$thb_theme_directory_uri. 'assets/img/logo.png' 

This is a theme option, and it points to the image file in the parent theme folder

To be able to fetch the image from your child theme directory, you need to change $thb_theme_directory_uri to $thb_stylesheet_directory_uri. Also, you must copy asset folder with image to the child theme too.

I'm not sure, but give it a try.

Also, if you want to make customization to your theme, you should ALWAYS do this from the child theme. If you want to add CSS, you should create CSS file inside child theme directory and enqueue it in your functions PHP file

wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/style.css' );

Like this and wrap it in function and add action hook wp_enqueue_scripts.

If you want to edit the theme PHP file, you should copy it to the child theme and make changes there. Be careful and follow-up folder structure.

Upvotes: 1

Related Questions