解决更新PHP7.X后Warning: Use of undefined constant px – assumed ‘px’

2022年04月21日 学习资料 暂无评论 阅读 608 次

WordPress从php5.6更新到7.x版本的时候,网站程序或者主题模板会出现一些警告错误,例如本博客升级php后在标签边栏出现报错如下:

Warning: Use of undefined constant px - assumed 'px' (this will throw an Error in a future version of PHP) in /www/wwwroot/oswhy.com/wp-content/themes/Ality/inc/functions/widgets.php on line 291

这个错误其实是px这个参数没有带引号导致的,php7.x以上的版本在引用参数时需要带引号,这个应该也是兼容性的问题。上面这个是用了第三方主题模板,模板的配置文件px参数没有带引号导致。正常主题模板都会随着php和wordpress版本进行更新,但是有些主题模板不更新的,就可以自己动手来解决,找到291这行代码。

<?php wp_tag_cloud( array ( 'order' => 'RAND', 'smallest' => '14', 'largest' => 14, 'unit' => px, 'number' => $number ) ); ?>

将px改为'px'保存即可。

其他一些升级更新php版本导致的网站报错,都可以自己摸索简单修改即可解决。

给我留言