我在twentyeleven主题中看到,在大多数自定义函数检查它是否存在之前
<?php if ( ! function_exists( \'twentyeleven_comment\' ) ) :
function twentyeleven_comment( $comment, $args, $depth ) {
为什么会这样?我在twentyeleven主题中看到,在大多数自定义函数检查它是否存在之前
<?php if ( ! function_exists( \'twentyeleven_comment\' ) ) :
function twentyeleven_comment( $comment, $args, $depth ) {
为什么会这样?子主题可能已经用稍微不同的内部逻辑声明了这些函数。这个functions.php
从子主题加载到从父主题加载的文件之前。如果没有此检查,您将得到“无法重新声明…”错误。
插件也可以创建函数,所以这个问题并不局限于在编写主题时考虑了子主题。