Skip to main content
simplified language
Source Link
cjbj
  • 15k
  • 16
  • 42
  • 89

I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it.

In the case of Yoast, it was a filter call to pre_get_document_title that returnedreturning non empty. In that case wp_get_document_title is short circuited anand the rest of the function, including the documents_title_parts filter, is not evaluated, as you can see from the first lines of code:

$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
    return $title;
    }

So, I took your filter and changed the hook to pre_get_document_title. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:

add_filter( 'pre_get_document_title', function( $title )
  {
    error_log('here');
    return $title;
 
  }, 999, 1 );

I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it.

In the case of Yoast, it was a filter call to pre_get_document_title that returned non empty. In that case wp_get_document_title is short circuited an the rest of the function, including the documents_title_parts filter is not evaluated, as you can see from the first lines of code:

$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
    return $title;
}

So, I took your filter and changed the hook to pre_get_document_title. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:

add_filter( 'pre_get_document_title', function( $title )
{
    error_log('here');
    return $title;
 
}, 999, 1 );

I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be another plugin is messing with it.

In the case of Yoast, it was a filter call to pre_get_document_title returning non empty. In that case wp_get_document_title is short circuited and the rest of the function, including the documents_title_parts filter, is not evaluated, as you can see from the first lines of code:

$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
    return $title;
    }

So, I took your filter and changed the hook to pre_get_document_title. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:

add_filter( 'pre_get_document_title', function( $title )
  {
    error_log('here');
    return $title;
  }, 999, 1 );
Bounty Ended with 50 reputation awarded by hookedonwinter
deleted 57 characters in body
Source Link
cjbj
  • 15k
  • 16
  • 42
  • 89

This may be just a partial answer, but perhaps it helps. I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it.

In the case of Yoast, it was a filter call to pre_get_document_title that returned non empty. In that case wp_get_document_title is short circuited an the rest of the function, including the documents_title_parts filter is not evaluated, as you can see from the first lines of code:

$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
    return $title;
}

So, I took your filter and changed the hook to pre_get_document_title. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:

add_filter( 'pre_get_document_title', function( $title )
{
    error_log('here');
    return $title;

}, 999, 1 );

This may be just a partial answer, but perhaps it helps. I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it.

In the case of Yoast, it was a filter call to pre_get_document_title that returned non empty. In that case wp_get_document_title is short circuited an the rest of the function, including the documents_title_parts filter is not evaluated, as you can see from the first lines of code:

$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
    return $title;
}

So, I took your filter and changed the hook to pre_get_document_title. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:

add_filter( 'pre_get_document_title', function( $title )
{
    error_log('here');
    return $title;

}, 999, 1 );

I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it.

In the case of Yoast, it was a filter call to pre_get_document_title that returned non empty. In that case wp_get_document_title is short circuited an the rest of the function, including the documents_title_parts filter is not evaluated, as you can see from the first lines of code:

$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
    return $title;
}

So, I took your filter and changed the hook to pre_get_document_title. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:

add_filter( 'pre_get_document_title', function( $title )
{
    error_log('here');
    return $title;

}, 999, 1 );
Source Link
cjbj
  • 15k
  • 16
  • 42
  • 89

This may be just a partial answer, but perhaps it helps. I ran your filter in my development area. It didn't work. Then I switched off the Yoast SEO plugin, which I knew was also messing with the page title. Then it worked. So my suggestion would be it is another plugin that is messing with it.

In the case of Yoast, it was a filter call to pre_get_document_title that returned non empty. In that case wp_get_document_title is short circuited an the rest of the function, including the documents_title_parts filter is not evaluated, as you can see from the first lines of code:

$title = apply_filters( 'pre_get_document_title', '' );
if ( ! empty( $title ) ) {
    return $title;
}

So, I took your filter and changed the hook to pre_get_document_title. It didn't work. Then I changed the priority to a higher level than the same filter in Yoast. Then it worked. So, I don't know about your set-up, but I suggest you give this a try:

add_filter( 'pre_get_document_title', function( $title )
{
    error_log('here');
    return $title;

}, 999, 1 );