Php 使用不同的wordpress函数而不是默认函数
您好,我知道这可能是一个显而易见的问题,但我只是想知道如何使用我自己在functions.php中创建的函数,而不是默认函数 为了解释我做了什么,我进入了wp includes/general-templates.php,并修改了Php 使用不同的wordpress函数而不是默认函数,php,wordpress,Php,Wordpress,您好,我知道这可能是一个显而易见的问题,但我只是想知道如何使用我自己在functions.php中创建的函数,而不是默认函数 为了解释我做了什么,我进入了wp includes/general-templates.php,并修改了get\u calendar中的许多代码 但是当我在网上读到更多的内容时,我意识到我不应该在用户更新到新的wordpress时就这么做,因为这些行可能会被覆盖 我保留了原始general-templates.php文件的副本。所以我想知道如何实现新的更新函数而不是gen
get\u calendar
中的许多代码
但是当我在网上读到更多的内容时,我意识到我不应该在用户更新到新的wordpress时就这么做,因为这些行可能会被覆盖
我保留了原始general-templates.php文件的副本。所以我想知道如何实现新的更新函数而不是general-templates.php中的函数
谢谢WordPress提供了两种不同的方法来覆盖默认函数输出:可插入函数和过滤器 可插拔函数 可插入函数(所有函数都位于
pluggable.php
)中)采用以下形式:
if ( ! function_exists( 'some_function' ) ) {
function some_function() {
// function code goes here
}
}
function some_function() {
// function code goes here
return apply_filters( 'some_function', $output );
}
要覆盖可插入函数,只需在您自己的插件(或主题的functions.php
文件,如适用)中定义它:
过滤器
过滤器采用以下形式:
if ( ! function_exists( 'some_function' ) ) {
function some_function() {
// function code goes here
}
}
function some_function() {
// function code goes here
return apply_filters( 'some_function', $output );
}
要覆盖筛选器,请定义回调并将其添加到筛选器:
function mytheme_filter_some_function( $output ) {
// Define your custom output here
return $output;
}
add_filter( 'some_function', 'mytheme_filter_some_function' );
专门针对get\u calendar()
如果您选择,您将看到的输出通过获取日历
过滤器传递:
return apply_filters( 'get_calendar', $calendar_output );
因此,您只需编写自己的回调来修改$calendar\u output
,并将其挂接到get\u calendar
function mytheme_filter_get_calendar( $calendar_output ) {
// Define your custom calendar output here
$calendar_output = '';
// Now return it
return $calendar_output;
}
add_filter( 'get_calendar', 'mytheme_filter_get_calendar' );
WordPress提供了两种不同的方法来覆盖默认函数输出:可插入函数和过滤器 可插拔函数 可插入函数(所有函数都位于
pluggable.php
)中)采用以下形式:
if ( ! function_exists( 'some_function' ) ) {
function some_function() {
// function code goes here
}
}
function some_function() {
// function code goes here
return apply_filters( 'some_function', $output );
}
要覆盖可插入函数,只需在您自己的插件(或主题的functions.php
文件,如适用)中定义它:
过滤器
过滤器采用以下形式:
if ( ! function_exists( 'some_function' ) ) {
function some_function() {
// function code goes here
}
}
function some_function() {
// function code goes here
return apply_filters( 'some_function', $output );
}
要覆盖筛选器,请定义回调并将其添加到筛选器:
function mytheme_filter_some_function( $output ) {
// Define your custom output here
return $output;
}
add_filter( 'some_function', 'mytheme_filter_some_function' );
专门针对get\u calendar()
如果您选择,您将看到的输出通过获取日历
过滤器传递:
return apply_filters( 'get_calendar', $calendar_output );
因此,您只需编写自己的回调来修改$calendar\u output
,并将其挂接到get\u calendar
function mytheme_filter_get_calendar( $calendar_output ) {
// Define your custom calendar output here
$calendar_output = '';
// Now return it
return $calendar_output;
}
add_filter( 'get_calendar', 'mytheme_filter_get_calendar' );
add_action()函数可能有帮助add_action()函数可能有帮助