Opened 11 months ago
Last modified 2 weeks ago
#61352 new defect (bug)
PHP deprecation notice in wp_title()
Reported by: | Owned by: | ||
---|---|---|---|
Milestone: | 6.9 | Priority: | normal |
Severity: | normal | Version: | 6.5.5 |
Component: | Themes | Keywords: | has- |
Focuses: | Cc: |
Description
I'm getting the following warning on what is currently the latest version of WordPress:
PHP Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /wp-includes/general-template.php on line 1425
This is the line in question:
$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
The PHP version is 8.2.
Attachments (1)
Change History (20)
#2 follow-up: โ 3
@
11 months ago
Perhaps it would be better to just do the Null coalescing operator
inside the explode.
<?php /** * Filters the parts of the page title. * * @since 4.0.0 * * @param string[] $title_array Array of parts of the page title. */ $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ?? '') );
This feels to me like what the code would have done in previous versions. And it would be compatible to php7.0.
#3 in reply to: โ 2
@
11 months ago
Replying to michaelreetz:
Yes that seems like a good approach!
#4
@
10 months ago
- Version changed from 6.5.3 to 6.5.5
Just to say that this is still happening in the latest version (6.5.5). I notice that the ticket status is currently "awaiting review" - how long does it normally take for a ticket to be reviewed?
#5
@
9 months ago
Just to say that this is still happening in 6.6.1, however the line number has now changed to 1440.
#7
@
7 months ago
Same here.
The problem occurs at least in my case when on custom route where there is no "title" parameter as it is on default WP views.
WP Version 6.6.2
#8
@
6 months ago
Still happening in 6.7.
When will this fix be applied ? This error is kind of annoying.

This ticket was mentioned in โSlack in #core by sirlouen. โView the logs.
3 weeks ago
#12 follow-up: โ 13
@
3 weeks ago
@sabernhardt
Setting a static blog page leaving the homepage set to --select-- instantly creates the issue and is easier to reproduce the issue than by recoding or adding code as mentioned above as "steps to recreate it".
I wonder why resolving this issue in the core code takes that long (more than 11 months) as the fix is easy and simple to apply and would have saved me a lot of time today.
Any theme using the wptitle function with a static blog page trigger the deprecated message.
Thank you
#13 in reply to: โ 12
@
3 weeks ago
Replying to neo2k23:
I wonder why resolving this issue in the core code takes that long (more than 11 months) as the fix is easy and simple to apply and would have saved me a lot of time today.
Long story short

This ticket was mentioned in โPR #8729 on โWordPress/wordpress-develop by โ@dhruvang21.
3 weeks ago #15
- Keywords needs-refresh removed
#16
@
3 weeks ago
- Milestone changed from Awaiting Review to 6.9
PR 8729 removes the deprecation notice and passes the tests.
I'll also suggest an alternative in case it might be better:
// If there is a post. if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) { $title = single_post_title( '', false ); if ( empty( $title ) ) { $title = ''; } }
#17
@
3 weeks ago
@sabernhardt This is all about wordpress being php compatible. Why checking for a empty($title) in above code as the cause of the problem is the filter with the explode call in general-template.php on line 1439.
The only logical fix would be checking $title before the filter is called or in that explode call on line 1439 and if $title is empty make sure its a empty string.
There are many cases why one can land on that line with $title == null.
The given solution in https://core.trac.wordpress.org/attachment/ticket/61352/general-template.diff
requires at least php 7.4 and i am not sure if the latest minimum requirement for php in wordpress already has been set to 7.4 or still is on 7.2
โhttps://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/
#18
@
2 weeks ago
- Summary changed from PHP deprecation warning in /wp-includes/general-template.php to PHP deprecation notice in wp_title()
My alternative suggestion, whether it includes empty()
or null === $title
, would only be a good idea if some situation should give an error (that is, if it ever indicates doing something wrong). I did not create a because I am not convinced my direction is better than PR 8729.
If this function's deprecation notice should be silenced in all cases,wp_resolve_block_style_variation_ref_values()
already established a precedent withexplode( '.', $value['ref'] ?? '' )
and comment:2 says that syntax is compatible with PHP 7.0.
#19
@
2 weeks ago
@sabernhardt you are right it was introduced in php 7.0 โhttps://www.php.net/manual/en/migration70.new-features.php
I doubt if one is interested in false doing it wrongs which also could be the case and as we have now when f.e. one sets a static blog page.
I rather see it silenced for all than getting these false incorrect deprecated messages. Moreover even if the title is empty the correct one is still presented after the filter has ran. Which was the case with the static blog page.
We are experiencing the same problem. It occurs on a dynamic post which we are creating on runtime.
Ways to reproduce:
And the single_post_title function returns null because of:
Possible solution
We could make the single_post_title function return a string value. But this does not solve the problem for other possible occurances of this error that are possibly triggered by the wp_title function. So that requires changing the functions below to always return a string instead of string|void:
As the default value of $title is already an empty string (and not null) in the wp_title function we could try this for each occurance of those functions in wp_title:
The Null Coalescing Assignment operator (??=) does require PHP 7.4 tho.
Hope this helps! :)