覆盖核心 WordPress 功能 - 应该可以,但不行
我正在尝试使用主题的functions.php 文件中的add_filter() 覆盖核心Wordpress 函数(在media.php 中找到)。这应该与我遇到的博客一致,但由于某种原因,我看不到任何变化。
#override what WP is trying to do to scaling images by default
function my_image_hwstring($width, $height) {
$out = '';
#if ($width)
# $out .= 'width="'.intval($width).'" ';
#if ($height)
# $out .= 'height="'.intval($height).'" ';
return $out;
}
add_filter('image_hwstring', 'my_image_hwstring', 1, 2);
我不喜欢手动编辑 media.php,因为稍后的任何 WordPress 升级都会覆盖我们所做的更改。我这样做的方式是正确的(我认为),但没有按预期工作。
完全挂断了这件事并感谢任何回应。这是一件奇怪的事!
I'm trying to overwrite a core Wordpress function (found in media.php) using add_filter() in my theme's functions.php file. This should work accord to the blogs that I've come across, but for some reason I see no change whatsoever.
#override what WP is trying to do to scaling images by default
function my_image_hwstring($width, $height) {
$out = '';
#if ($width)
# $out .= 'width="'.intval($width).'" ';
#if ($height)
# $out .= 'height="'.intval($height).'" ';
return $out;
}
add_filter('image_hwstring', 'my_image_hwstring', 1, 2);
I prefer to not edit media.php manually because any Wordpress upgrades later will overwrite the changes we've made. The way I'm doing it is correct (I think) but isn't working as expected.
Totally hung up on this and appreciate any responses. This is a weird one!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试连接的核心函数的名称是什么?这些可能会有所帮助:
WordPress 2.9 - 所有挂钩和过滤器列表 和 PHP 交叉引用 (PHPXref):WordPress 2.9.1
What's the name of the core function you're trying to hook into? These might help:
WordPress 2.9 - List of all hooks and filters and PHP Cross Reference (PHPXref) of: WordPress 2.9.1
只是为了澄清这一点,您没有运行任何形式的缓存系统,对吧?喜欢 wp-cache 或 wp-super 缓存这样的缓存插件吗?如果是这样,请尝试清除/刷新缓存。
Just to clear the obvious, you're not running any form of cache system right? Like a cache plugin like wp-cache or wp-super cache? If so, try clearing/flushing the cache.