I'm trying to make a post display some PHP code example. Using WordPress 5.2.1 with PHP 7.3
The website works fine otherwise. However, when I'm editing a post, select "Formating - Code" and enter some PHP code within the block, it won't save the updated post version.
"updating failed".
Has anyone else had this problem? Tried disabling WordFence - didn't help.
So it's either the (shared) hosting provider, or something with the WordPress.
EDIT: The "problematic" code example:
// BEGIN Google Analytics
function ns_google_analytics() { ?>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXX-X');
</script>
<?php
}
add_action( 'wp_head', 'ns_google_analytics', 10 );
// END Google Analytics
To avoid misunderstanding: My attempt is/was to display the code in a post, like it is displayed here. When implementing it on a website, this goes into child theme's functions.php. But the post I'm trying to write is a tutorial one and should display the code sample so it can be easily copied by any visitor. The code (as shown) is not supposed to run on that post.