3

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!!

2
  • Not sure why there's a closing an opening PHP tag, there should only need to be a single opening tag right at the beginning Commented Aug 16, 2018 at 23:04
  • Do you mean there only needs to be the 1st opening and closing PHP tag? I have now removed the second set, but it hasn't made a difference Commented Aug 17, 2018 at 0:22

1 Answer 1

5

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'; } 
1
  • Thank you that has done it! I will remember that from now on, and not make the same silly mistake again! Commented Aug 17, 2018 at 18:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.