假设我有一个这样的函数:
add_filter("post_gallery", "fix_my_gallery_wpse43558",10,2);
function fix_my_gallery_wpse43558($output, $attr) {
// blah, blah, blah
}基本上,上面的函数允许我使用post_gallery过滤器覆盖内置的(也称为默认) WordPress图片库模板。
问题是,我只想在我的自定义提要中覆盖默认的WordPress图片库模板,为此我需要使用if ( is_feed( $feeds = 'custom_feed' ) ) { .... }条件标记。
问题是,在条件标记内操作函数的正确方式是什么?
if ( is_feed( $feeds = 'custom_feed' ) ) {
add_filter("post_gallery", "fix_my_gallery_wpse43558",10,2);
function fix_my_gallery_wpse43558($output, $attr) {
// blah, blah, blah
}
}或
add_filter("post_gallery", "fix_my_gallery_wpse43558",10,2);
function fix_my_gallery_wpse43558($output, $attr) {
if ( is_feed( $feeds = 'custom_feed' ) ) {
// blah, blah, blah
}
}发布于 2012-09-03 18:49:27
我会采用您的第一个解决方案,因为filter-function只需要在提要中执行。
但是没有“正确的方法”,因为两种解决方案都应该在…中工作。
发布于 2012-09-03 18:50:49
我会使用第一个。它会更快,因为过滤器会在不需要的时候被忽略。
此外,在第二个示例中,您还需要抛出$output,从速度的角度来看,这又有点浪费。
https://stackoverflow.com/questions/12246331
复制相似问题