Changes to functions.php not working

I am trying to make changes to my functions.php file.
I have just set up my child theme for the Sydney theme, and have tested the stylesheet and that is working fine.
I am looking to make changes to my woocommerce checkout page and was literally just creating an echo to make sure it is working…
I tried using the child theme configurator plugin to set up my child theme and make sure there were no errors in my code (as I couldn’t make my stylesheet work either)

This is my functions.php:

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

// BEGIN ENQUEUE PARENT ACTION // AUTO GENERATED - Do not modify or remove comment markers above or below: // END ENQUEUE PARENT ACTION  add_action ('woocommerce_before_checkout_form','add_content_above_checkout',15); function add_content_above_checkout () {  echo 'TEST'; }

That second “php” statement was added by the child theme configurator for some reason as well, although it hadn’t closed the statement so I added the closing ?>

If there’s anything visibly wrong, let me know!!

1 Answer
1

Closing PHP tag and then opening in the next line:

Whenever there is something (even space, tab, newline etc.) after a closing PHP tag ?> or before an opening PHP tag <?php, PHP engine considers it as output.

So the way your code is, it’ll generate some unnecessary output, that often throws error or warning like:

Header already sent …

So you must make sure there is no unintended output, even if you need multiple opening and closing PHP tags.

Closing PHP Tag ?>

PHP doesn’t need the closing PHP tag ?>.
If the file ends while within the scope of any opening PHP tag <?php, PHP considers the file ending to be the end of the PHP tag.

CODE fix:

So in that light, your CODE will be like:

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

    // BEGIN ENQUEUE PARENT ACTION
    // AUTO GENERATED - Do not modify or remove comment markers above or below:
    // END ENQUEUE PARENT ACTION
    add_action('woocommerce_before_checkout_form', 'add_content_above_checkout', 15);
    function add_content_above_checkout () {  echo 'TEST'; }

Leave a Comment