I'm not new to Wordpress and I make my own theme, but the old way... Not as a Block Theme.
I'm trying to move on to Block Theme, And I'd like to know if there any simple possibility to add some custom class to Footer and/or Header (html tag), when using block-theme parts??
I've been searching the developer Handbook but nothing conclusive (surely missed something), I also tried to look at the code and found a filter responsible for adding default classes based on the block name block_default_classname
but it does not differentiate template-part.
There is also the wp_apply_custom_classname_support
function which is the closer to what I want, but I do not understand how to add the block attribute className
for the <footer>
or the <header>
template-part.
EDIT: For maybe more explanation, here is how is made my theme and how is called the header and footer:
- themeFolder/
- parts/
- header.html
- footer.html
- templates/
- index.html
- ...
- parts/
index.html
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->
header.html
and footer.html
are empty as they are "populated/created" from the editor inside the admin.
All I want is to be able to add some classes along the one added by WP (wp-block-template-part
) when the template part block is rendered
<footer class="wp-block-template-part">....</footer>
I'm not new to Wordpress and I make my own theme, but the old way... Not as a Block Theme.
I'm trying to move on to Block Theme, And I'd like to know if there any simple possibility to add some custom class to Footer and/or Header (html tag), when using block-theme parts??
I've been searching the developer Handbook but nothing conclusive (surely missed something), I also tried to look at the code and found a filter responsible for adding default classes based on the block name block_default_classname
but it does not differentiate template-part.
There is also the wp_apply_custom_classname_support
function which is the closer to what I want, but I do not understand how to add the block attribute className
for the <footer>
or the <header>
template-part.
EDIT: For maybe more explanation, here is how is made my theme and how is called the header and footer:
- themeFolder/
- parts/
- header.html
- footer.html
- templates/
- index.html
- ...
- parts/
index.html
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->
header.html
and footer.html
are empty as they are "populated/created" from the editor inside the admin.
All I want is to be able to add some classes along the one added by WP (wp-block-template-part
) when the template part block is rendered
<footer class="wp-block-template-part">....</footer>
Share
Improve this question
edited Feb 5 at 13:35
La Fabrique Info
asked Feb 5 at 10:38
La Fabrique InfoLa Fabrique Info
113 bronze badges
6
|
Show 1 more comment
1 Answer
Reset to default 1After some trial and error here is what I was looking for.
So to add classes to some Template Part Block (like header and footer), you can (cause it is surely not the only solution) add the attribute className
to the markup.
<!-- wp:template-part {"slug":"footer","tagName":"footer", "className":"foo bar baz"} /-->
foo
orbar
classes, how to do it? This is the question I'm looking answer for. – La Fabrique Info Commented Feb 5 at 11:06