• Hi All,

    I have tried to create a new theme based on full site editing ( Block theme – as introduced here https://developer.wordpress.org/block-editor/how-to-guides/themes/block-theme-overview/ ).

    The problem is that in this type of theme we just create html pages inside block-templates and block-template-parts folder. There is now no more header.php and footer.php files in the them, where we can easily include our php files like include_once(get_template_directory() . '/js/customjs.php') ;

    Now how we can do such thing in the new Block theme ?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Topher

    (@topher1kenobe)

    For things like javascript you should always be using wp_enqueue_script() even with the old way of doing things.

    For including PHP and other files, I have no idea. 🙁

    Hi

    If you can explain what you are trying to accomplish perhaps we can guide you to the best option.

    Thread Starter hozefasmile

    (@hozefasmile)

    Hi @poena and @topher1kenobe

    I have found my own why to include php files at various places in the new block theme.

    function uni_add_footer_file(){
        include_once(get_template_directory() . '/js/conditionaljs.php') ;    
    }
    add_action('wp_print_footer_scripts', 'uni_add_footer_file', 10, 0);
    function uni_add_afterbody_file(){
        include_once(get_template_directory() . '/afteropenbody.php') ;    
    }
    add_action('wp_body_open', 'uni_add_afterbody_file', 10, 0);
    function uni_add_beforeheadclose_file(){
        include_once(get_template_directory() . '/css/conditionalcss.php') ;    
    }
    add_action('wp_head', 'uni_add_beforeheadclose_file', 10, 0);

    This way I can insert any custom php code at before head closing tag , after body opening tag and at before body closing tag, which are now not directly accessible in block theme due to absent of header.php and footer.php files.

    I am utilizing it to put conditionally put some css and js scripts based on the page and block being used on the page, we can also add any custom php output at those locations using this same method 🙂

    Thread Starter hozefasmile

    (@hozefasmile)

    one last limitation remain is inserting some php code inside the post or page template itself, for that we can utilize this simple plugin for php block https://wordpress.org/plugins/php-everywhere/, that then can be inserted in the template.html pages of the theme itself.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Fullsite Editing Themes ( Block Theme ) – how to include php files ?’ is closed to new replies.