• Hey WP

    I have a block theme official WP TT4. I also have a loose canon of a PHP page that displays without any integration into my theme. So I would like to make a new custom template that has my header and footer and then simply throw this php content into that template. I am not a PHP coder, sorry, but I can delete or copy paste a line of code. I just need this seamless integration.

    The loose canon php file is located in a custom folder inside themes > tt4 > …. so it should not get overwritten at upgrades.

    First things first, but more advanced step 2, I would like to create 2 different themes of loose canon php. This could be for example Light / Dark theme. Should I

    • Create those strictly in CSS? And how can I then allow a user to select light / dark
    • Create a copy of Loose Canon php and do things in there? and how can user A, B and C then select their individual theme
    • Create 2 templates in block theme and then style in there and css. How can I then make the themes (templates) selectable by user.

    Any suggestions will be a great help. Even better, if someone will share a few snippets to do this, that’s just perfect. I guess, I am not the only one with this need…

    Thx

Viewing 1 replies (of 1 total)
  • So I would like to make a new custom template that has my header and footer and then simply throw this php content into that template.

    Full-Site Editing (aka Block) theme templates cannot have PHP code. So rather than bringing your PHP code to your block theme’s template, you’ll need to do the opposite: take your block theme’s template parts (header, footer, sidebar, etc) to a traditional PHP custom page template.

    • Create a traditional PHP custom page template, and include your “Loose Canon” PHP code/file here.
    • Use block_template_part() or something similar to bring your TT4 block theme’s template parts (header, footer, sidebar, etc) into this PHP template.

    Here’s an excellent resource that walks you through this: https://fullsiteediting.com/lessons/how-to-use-php-templates-in-block-themes/

    The loose canon php file is located in a custom folder inside themes > tt4 > …. so it should not get overwritten at upgrades.

    Nope.

    During a theme update, the entire theme directly is replaced… so putting your files in a custom directory inside the theme directory isn’t going to help you. The solution is to use a child theme instead.

    An alternative to bringing in your “Loose Canon” PHP code via a custom PHP template in a child theme is to turn it into a little plugin and create a custom block or shortcode for it. You can then insert the custom block or shortcode directly into any of your TT4 block theme templates (built-in or a custom one you create from Site Editor).

    As for the dark/light modes, you’d do your designs in CSS as normal, and have a bit of JavaScript and HTML to implement the toggle. The TT4 theme comes with 10 styles (colour variations), including light (default) and dark ones, so the CSS is there already. All that’s missing is a front-end button and a bit of JS to do the actual switching.

    Good luck!

Viewing 1 replies (of 1 total)
  • The topic ‘Add php file inside my-theme inside a block template’ is closed to new replies.