0

A function in the parent functions.php is requiring an include. I have editted this file its calling, but obviously its still in the parent directory.

require get_template_directory() . '/inc/widgets/team-member.php';

How can i ammend the file url in the child functions.php?

1 Answers1

0

Add this code in parent theme functions.php

add_action( 'wp_loaded', 'parent_prefix_load_classes', 10 );

function parent_prefix_load_classes()
{
   define('MEMBER_FILE_URL', get_template_directory(). '/inc/widgets/team-member.php');
}

Use this code in chile theme

// Priority 11 to run after the parent theme's loader.
add_action( 'wp_loaded', 'child_prefix_create_objects', 11 );

function child_prefix_create_objects()
{
    echo MEMBER_FILE_URL;
}
Vel
  • 9,027
  • 6
  • 34
  • 66
  • why use `require`, but not `require_once`? – Samvel Aleqsanyan Jan 11 '18 at 10:38
  • also, this answer is best of this type requiring https://wordpress.stackexchange.com/a/199425/133553. of course, if he can wait until all parent theme functions finished work – Samvel Aleqsanyan Jan 11 '18 at 10:41
  • 1
    Why add define? Calling `get_template_directory ()` in the child theme will still return the same parent directory. And I doubt this is what OP is asking for, but to be honest I have no clue what OP is asking. – René Jan 11 '18 at 11:00
  • @SamvelAleqsanyan https://stackoverflow.com/questions/2418473/difference-between-require-include-and-require-once - in many cases it hardly matters. Whenever I actually need *_once it's probably because of a flaw in my code. – René Jan 11 '18 at 11:09