WordPress / wporg-developer

WordPress.org Developer theme
https://developer.wordpress.org/
60 stars 23 forks source link

Function name not displayed in google search results #479

Open benniledl opened 8 months ago

benniledl commented 8 months ago

Hey, when I google: _wp_filter_build_unique_id for some reason the function name is not in the title, its just this:

Screenshot 2024-01-18 at 13-54-35 _wp_filter_build_unique_id - Google Suche

This shouldn't happen, other functions work fine:

Screenshot 2024-01-18 at 13-55-05 get_post - Google Suche

I am not sure on which pages this applies but maybe someone has a thought on why this happens?

benniledl commented 8 months ago

I think maybe this generally affects functions with a _ prefix this is _custom_background_cb for example Screenshot 2024-01-18 at 14-17-38 _custom_background_cb - Google Suche

ryelle commented 8 months ago

The title tag should include the function in both cases, so it's not a problem with the site. I wonder if Google thinks it's not a real part of the title.

We could switch up the code reference entry titles to prefix with the reference type, like "Function: _the_function_name() | Developer.WordPress.org" ? That way it wouldn't start with the underscore.

@eidolonnight @thetinyl What do you think?

eidolonnight commented 8 months ago

I don't think it's the underscore that's a problem. Here is an example from the Drupal project docs: _forum_icon | forum.module | Drupal 4.6 | Drupal API

CleanShot 2024-01-18 at 15 30 59@2x

This does appear to be happening with other pages though, like _wp_cron.

ryelle commented 8 months ago

True, when I search for _wp_cron, it appears in the second result's title.

Screenshot 2024-01-18 at 3 39 01 PM

But I'm not sure what we're doing differently, because we have the full title in <title> (and og:title, if that's worth anything here).

Screenshot 2024-01-18 at 3 39 35 PM
eidolonnight commented 8 months ago

Were changes recently made to these pages? Perhaps it just needs to be re-indexed. Everything is looking fine currently.

benniledl commented 8 months ago

Maybe Google becomes confused due to the presence of multiple different titles, thinking it's inconsistent and it needs to figure out the title itself. It seems to extract the page name "Function" (stripping the seemingly wrong string starting with _) from the <title> tag and then derives the site name from other elements such as <link rel="alternate">, combining them, trying to take it's best guess. Maybe if we take the exact same title in every element, google will "trust" the title and not try to make its own guess??

Screenshot 2024-01-18 222939

For example this site: https://wp-kama.com/function/_wp_cron Has the exact same string in every title element.

ryelle commented 8 months ago

Were changes recently made to these pages?

There was https://github.com/WordPress/wporg-developer/pull/399, but it didn't change the title on these pages.

One thing I noticed while looking is that Google is changing the title slightly. It has the sections separated by -, rather than the |. For example, the page has <title>get_theme() – Function | Developer.WordPress.org</title>, but google shows:

Screenshot 2024-01-18 at 4 47 27 PM

Oh, the suffix is different too- I just caught it because of @benni1516's screenshot (thanks!). It uses that site_name value for the last segment, "WordPress Developer Resources" rather than "Developer.WordPress.org".

So google is definitely adjusting the title. Maybe it sees the h1 on the page is "_wp_cron(): int|false" and decided that isn't a human-friendly string? I'm not sure why the Drupal & wp-kama sites work, though, if that's the case.

benniledl commented 8 months ago

I think it strips _wp_cron() - because it is not a human-friendly string (as you said) and then it rather takes the sitename WordPress Developer Resources rather than the domain name because that is also a more human-friendly string.