[wp-trac] [WordPress Trac] #57422: get_body_class() adding class "{$post_type}-template-{dir}{file}"

WordPress Trac noreply at wordpress.org
Thu Jan 5 14:32:28 UTC 2023


#57422: get_body_class() adding class "{$post_type}-template-{dir}{file}"
-------------------------------+------------------------------
 Reporter:  arrancurran        |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  6.1.1
 Severity:  minor              |  Resolution:
 Keywords:                     |     Focuses:  css, template
-------------------------------+------------------------------
Changes (by sabernhardt):

 * keywords:  changes-requested =>
 * component:  General => Posts, Post Types


Old description:

> When is_singular() and is_page_template() and the template file is inside
> a directory within the theme folder, get_body_class() adds a class with a
> missing hyphen between the template directory and the template file name.
>
> post-template.php line 677;
>
> $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace(
> '.', '-', $template_slug ) );
>
> Example: post_type is page and template file is, "page-templates/my-
> template-file.php"
>
> Result: .page-template-page-templatesmy-template-file-php
>
> Suggested change to post-template.php line 677;
>
> $classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace(
> array( '.', '/' ), '-', $template_slug ) );

New description:

 When `is_singular()` and `is_page_template()` and the template file is
 inside a directory within the theme folder, `get_body_class()` adds a
 class with a missing hyphen between the template directory and the
 template file name.

 `post-template.php` line 677;

 `$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace(
 '.', '-', $template_slug ) );`

 Example: `post_type` is page and template file is, `page-templates/my-
 template-file.php`

 Result: `.page-template-page-templatesmy-template-file-php`

 Suggested change to `post-template.php` line 677;

 `$classes[] = "{$post_type}-template-" . sanitize_html_class( str_replace(
 array( '.', '/' ), '-', $template_slug ) );`

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57422#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list