I am trying to create a single.php file to be the default template for displaying single posts in a child theme that I have created from the TwentyTwentyThree theme. The reason I want to set this as the default is I have a lot of custom css used for the navbar that is a real pain to get working with the new editor, so I just want to have the single.php file that I can use to display the content as default. The code required is rendered in my header.php file and works well for the page templates, like front-page.php or other custom templates which I have created and is working fine Is there a way to do this?
I know that the block themes work a little differently but I thought that the hierarchy would still apply and I like the other features of the theme so I would like to keep it.
Here is the code for the single.php file:
<?php get_header(); ?> <article class='content px-3 py-5 p-md-5'> <?php if( have_posts() ){ while(have_posts()){ the_post(); the_content(); } } ?> </article> <?php get_footer(); ?>
.htmltemplate files and block templates. I'd recommend you work entirely within the site editor for as much as possible, you can always enqueue additional CSS/JS, as well as add classes to blocks to apply that CSS. Putting CSS in aheader.phpis bad practice even when using PHP templatestheme.json, not with new CSS. At all costs avoid inline CSS be that when you write it in the UI or insert it into files in the theme manually, that's true of both block themes and classic themes. As far as block themes are concerned the pain usually occurs because it's difficult to do something you don't need to do or shouldn't be doing. E.g. don't try to write CSS to adjust margins and paddings on the header, use the block editor controls