• I’m picking up WordPress and trying to dive in with Blocks and themes. I am trying to integrate The Event Calendar (TEC) into the Fork (block editor) theme and have got confused. I understand most of how to do what I want in the Block Editor.

    TEC has blocks and does some of what I want but I wanted to tidy up the display of the data. It suggests using hooks for certain customisations and has some code examples. TEC has template overrides in the tribe folder under the template, so seems to be isolated from template updates.

    I’d started off deciding that as I was using Blocks I didn’t need a child template, so merrily did some experimentation in Fork. As I understand it the customisation is stored in the database.

    However, if I want to use hooks, I presume that goes in functions.php

    But, now I am bothered because I don’t want to update functions.php in Fork.

    As a general point, I’m a bit confused under the Site Editor where you put PHP code if you want to add functionality without altering the template itself.

    As a workaround, I thought I would create a child theme from Fork so I created Fork-child using the Create Block Theme and then I’ve got a place to alter functions.php, but that seems to have broken the site as the header and footer appear in the editor (and can be edited) but do not display on the Visit site option (they reappear if I flip the site template back to Fork). That might be a different point and really what I want is a minimally edited site with as little customisation as possible, preferably without child themes if possible.

    So the simple question is in the Block Editor, what is the correct way to add PHP code for actions like the TEC plugin filter code?

Viewing 1 replies (of 1 total)
  • In the Block Editor and Full Site Editing (FSE) context, you’re correct that most customizations are stored in the database. However, when you need to add custom PHP code, such as hooks for plugins or custom functionality, you will still need to modify your theme’s functions.php file or create a child theme to avoid losing your custom code when the parent theme is updated.

    To add custom PHP code for actions and filters, you should create a child theme. Here are the steps to create a basic child theme:

    1. Create a new folder: In your wp-content/themes directory, create a new folder for your child theme, e.g., fork-child.
    2. Create a style.css file: In the fork-child folder, create a style.css file with the following header:
    /*
    Theme Name: Fork Child
    Template: fork
    */
    

    Replace fork with the actual directory name of your parent theme, if it’s different.

    3. Create a functions.php file: In the fork-child folder, create a functions.php file. In this file, you can add your custom PHP code, such as hooks and filters for The Events Calendar plugin. To enqueue the parent theme’s styles, add the following code to your child theme’s functions.php file:

    <?php
    add_action( 'wp_enqueue_scripts', 'fork_child_enqueue_styles' );
    function fork_child_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
    

    You can then add your custom PHP code below this.

    4. Activate the child theme: In your WordPress dashboard, go to Appearance > Themes and activate your new child theme.

    By following these steps, you’ll have a minimal child theme that doesn’t affect the parent theme, allowing you to add custom PHP code while retaining the ability to update the parent theme without losing your changes.

    Regarding the issue with the header and footer not displaying when you created a child theme using the Create Block Theme method, it might be due to the way that method creates the child theme. The method above should create a minimal child theme that works correctly with your parent theme.

Viewing 1 replies (of 1 total)
  • The topic ‘Block Theme customisation’ is closed to new replies.