Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template part general area causes php error. #49407

Open
dabowman opened this issue Mar 28, 2023 · 3 comments
Open

Template part general area causes php error. #49407

dabowman opened this issue Mar 28, 2023 · 3 comments
Labels
[Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement.

Comments

@dabowman
Copy link

Description

When I assign a template part to general in theme.json like this:

		{
			"name": "content",
			"title": "Content",
			"area": "general"
		},

I get a php error on the front end like this:

“general” is not a supported wp_template_part area value and has been added as “uncategorized”.

If I change the value in theme.json to "area": "uncategorized" the error goes away.

Shouldn't general be a supported template part area value? You can select it in the site editor. I'm not sure why doing it in code causes an error.

Step-by-step reproduction instructions

  1. assign template part area to "general" in theme.json
  2. load page using template part
  3. check php error logs.

Screenshots, screen recording, code snippet

No response

Environment info

WordPress: 6.1.1
Gutenberg: 15.0.1
Theme: Valet (custom)

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

@kathrynwp kathrynwp added [Type] Enhancement A suggestion for improvement. [Block] Template Part Affects the Template Parts Block labels Mar 28, 2023
@Mamaduka
Copy link
Member

The area slug for General is the uncategorized. See the area definitions https://developer.wordpress.org/reference/functions/get_allowed_block_template_part_areas/.

IIRC, the label was updated later, and the slug was kept for backward compatibility.

@carolinan
Copy link
Contributor

carolinan commented Apr 27, 2023

I propose opening this as a new documentation issue for the theme developer handbook, and closing this issue.

Currently the documentation only says

Template parts can use the following attributes:

slug: Used to identify the template part
theme: The theme slug. Used to identify the template part when the part is placed outside a template, for example in a block pattern.
area: Select between uncategorized (general), header and footer
tagName: The HTML tag. Select between header, main, section, article, aside, footer and div.

And the theme.json documentation says:

You assign default template parts to template areas in the templateParts section.
Add three keys: name, the file name of the template part file without the file extension,
area, the name of the template area, and title, the visible name in the editor.
There are three template areas to choose from: header, footer, and uncategorized (general).

So there is room to clarify uncategorized and general.

@strarsis
Copy link
Contributor

strarsis commented Jun 10, 2024

I encountered a similar issue with current WordPress core:

{
  [...]
  "templateParts": [
    {
      "name": "example",
      "title": "Generic example"
    }
  ]
}

When "area": "uncategorized" is omitted as uncategorized should be the default (and worked in previous versions),
the following PHP Notice is emitted: "" is not a supported wp_template_part area value and has been added as "uncategorized"..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement.
5 participants