0

I want to change a php file in a subdir of my theme folder. The path to that specific file is:
/includes/sf-content-display/sf-post-formats.php

I copied the file within the subdirs in my child theme and made the changes.

It seems, if I read some articles, that I have to hook a selfmade function in a file functions.php in the child theme.

I did the folowing:

function require_once_child() {
    require_once('includes/sf-content-display/sf-post-formats.php');    
}

function require_once_child() {
    remove_action( 'init', 'require_once' );
    add_action( 'init', 'require_once_child' );
}
add_action( 'init', 'require_once_child' );

Result is an error:

Fatal error: Cannot redeclare require_once_child() (previously declared in /www/htdocs/keltenwo/wp/wp-content/themes/flexform-child/functions.php:3) in /www/htdocs/keltenwo/wp/wp-content/themes/flexform-child/functions.php on line 9

Any suggestions?

1
  • 1
    You are including a PHP by editing style.css? Please clarify this question.
    – s_ha_dum
    Commented Aug 11, 2013 at 16:10

1 Answer 1

0

Any suggestions?

For one, read and interpret the error message.
"Cannot redeclare require_once_child()" is pretty straightforward: Don't give two functions the same name.

I am uncertain whether your general idea is sensible in the first place, but should it be, this

function require_once_child() {
    require_once('includes/sf-content-display/sf-post-formats.php');    
}
add_action( 'init', 'require_once_child' );

is all you need.

1
  • Thanks Johannes, It make sence. I have included this function above but i get the next message: Fatal error: Cannot redeclare sf_get_post_media() (previously declared in /www/htdocs/keltenwo/wp/wp-content/themes/flexform/includes/sf-content-display/sf-post-formats.php:15) in /www/htdocs/keltenwo/wp/wp-content/themes/flexform-child/includes/sf-content-display/sf-post-formats.php on line 36 It seems the function sf_get_post_media() is already declared. Commented Aug 12, 2013 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.