English 中文(简体)
Wordpress 儿童主题: 超过函数
原标题:Wordpress child theme: override functions

在我的父母主题中,我有一个功能 没有初始声明:

if (!function_exists(... etc...

How can I replace it with a function with the same name in my child theme? If I create the function into my functions.php it gives me an error due to the fact that there are two functions with the same name.

提前感谢您的回答。

问题回答

这似乎对我有用:

function fileExistsInChildTheme($file_path){
    $file_directory = get_template_directory();
    if(file_exists($file_directory . "-child" . $file_path)){
        return $file_directory .= "-child" . $file_path;
    }
    return $file_directory .= $file_path;
}

require ( fileExistsInChildTheme( /includes/functions.php ) );
require ( fileExistsInChildTheme( /includes/theme-options.php ) );
require ( fileExistsInChildTheme( /includes/hooks.php ) );
require ( fileExistsInChildTheme( /includes/version.php ) );

child 主题函数.php 文件在父主题函数文件前装入了 < 坚固> , 因此您不应该在重新声明子主题中的函数时遇到致命错误。 这就是为什么您的父主题正在使用 < code> 函数_ explocations check 。

也许你是在钩子(如Init)之后 宣布儿童主题中的函数?

有关此的编码文件如下:http://codx.wordpress.org/Child_Themes#Reference_2F_Including_Files_in_Your_Child_Theme

i 认为,如果您加入相同的函数名称,它取自子主题函数,取自母函数。

对前妻来说

<强力 > 儿童主题

if ( ! function_exists(  function_name  ) ) {
  function function_name(){
    echo  This is child theme ;
  }
}

<强力 > 父母主题

if ( ! function_exists(  function_name  ) ) {
  function function_name(){
    echo  This is parent theme ;
  }
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签