It is bad practice to end a PHP only file with the PHP closing tag (?>) as it may lead to a new line or any other character being output before the headers or other functions and thus creating problems like the one you mention.
Whenever you create/edit a PHP file, don’t close it, if you have to include HTML, close and open the PHP tags again.
https://php.net/basic-syntax.instruction-separation
The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include or require, so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.
Best regards.
Related Posts:
- Fatal error: Call to undefined function plugin_dir_path()
- Dynamic URL to reference custom PHP files
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- Using wp_get_image_editor in a standalone script
- New Plugin Review
- Making Quote Plugin more efficient
- How to access function from outside of a class within this class in WP plugin?
- PHP can I add line numbers to file_get_contents()
- Adding Default Settings to Theme My Login plugin
- Swapping wp_dropdown_categories function with wp_category_checklist
- How to access global variable $menu inside a class function
- How can I remove a function that has been added to wordpress with add_filter?
- what is the best practice to add new field to an api route
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- How to call plugin function per site in a multisite?
- WordPress Custom field Colors
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- How to use html inside a functions.php code?
- Using data sent via AJAX in multiple functions on a WP plugin
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Custom meta box values are not getting saved for my custom post type
- how to save checkbox data for custom setting?
- Call to undefined function error in plugin
- Execute Jquery when a specific page in my plugin is loading
- send popup after wp_redirect()
- Using ACF Relationship field to set post type to draft or published status
- How to change basename url for wp-admin?
- How to Send Pingbacks for all Posts in WordPress?
- Reliable way to add nonce to HTTP Header in WordPress?
- Only the first image uploads
- Add Pre-Defined Value to Click Counter in WordPress
- Illegal string offset checkbox
- ssl redirect function is not working
- Custom plugin: how do I call a PHP file if settings option is set to true?
- How can i avoid duplicate same post in wp?
- Display a custom name when the user has no name settle in his account
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- How to override theme’s public static function inside of a trait?
- Enqueue sripts and styles only if function is called
- post_exists stops working in a scheduled event
- Taxonomy Child Term, Counter is staying on 0
- PHP get_category() function redeclared
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Permission error on plugin save
- Trouble using wordpress functions in a pop-up modal form
- Issues separating my Plugin pages into different files
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- display php code in header using wp_head()
- How do I change the Go To Categories link in the term_updated_messages
- WP Custom tables query
- Using register_activation_hook in classes
- How to get the original price of the product in woocommerce?
- How to add 2 posts under another post? Formatting should be intact
- Get widget settings function?
- What is the fastest way to load PHP functions that are only used in one theme template?
- Adding tawk.to code just before body tag on functions.php file
- WP nonce invalid
- add_action shortcut?
- Get page that displays all children of taxonomy parent
- Function to capture a value and store it in a variable
- My new button is in the wrong place
- Checking array against author id in loop
- How do I link a button I created in theme customizer to a function?
- execute function after one completed
- Custom Pagination is Broken
- wordpress admin plugin menu custom css
- Why i can’t get custom fields value or post ID via Ajax?
- Fallback image URL if no featured image exists via a shortcode function
- Deactivate a plugin on wp version
- the_post_thumbnail issues
- Some problems calling a function into sprintf() inside functions.php template file [closed]
- WP insert post Redirect after function has executed
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- Payment field disappears on custom Paypal plugin
- HTML comment cause issue in functions.php script root
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Handling form actions in WordPress
- Set user status to absent on WordPress
- Shortcode’s output to use as other shortcode’s parameter
- Displaying POST content with HTML tags and all
- Showing wordpress latest post thumbnails in slider with auto increment
- My function echos only “array”
- Notify admin (by email) if post added with specific tag
- Retrieving specific images from Media Library
- Can’t put a hyperlink on Featured Post’s Image
- WordPress HTML Helper
- See output of a sql query while plugin installation in wordpress
- List sibling pages widget, exclude current page
- Doing action based on input from options menu
- Send foreach $_post method to contact form 7 [closed]
- Too few arguments at registering new templates in my plugin
- Automatically change insurance quantity based on cart total [closed]
- I want to lists posts in wordpress to nearest location entered by the user
- hiddenQuestions.find is not a function