I generated a WordPress plugin. However: When I include css and js file I get an error when I edit a page where I added the shortcode. So what I do: I create a page, add the shortcode, it loads the plugin and my Hello World text. But then, when I save the edited page, it shows the error, hat there were errors during saving and this could be up to server limitations. But I am pretty sure, it has nothing to do with that. Also it does not matter what theme or builder I use. (Mostly I use Divi)
So the question is: Do you see any error in my plugin code? In folder plugins I have a folder called "myPlugin" containing a main.php containing this code:
<?php
/*
* Plugin Name: My Plugin
* Plugin URI: https://example.com
* Description: A brief description of my plugin
* Version: 1.0.0
* Author: Your Name
* Author URI: https://example.com
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: my-plugin
* Domain Path: /languages
*/
function my_shortcode_function() {
echo "<p class='myxxx'>Hello world</p>";
}
add_shortcode('my_shortcode', 'my_shortcode_function');
function my_plugin_init() {
wp_enqueue_style('my-plugin-style', plugins_url('css/style.css', __FILE__));
wp_enqueue_script('my-plugin-script', plugins_url('js/script.js', __FILE__));
}
add_action('wp', 'my_plugin_init');
The css file styles.css contains only:
/* css file */
.myxxx { color:red; }
Very important: On lets say page /test I put [my_shortcode] to run the plugin. Works. It shows in red "Hello World". BUT when I save its giving the saving error. (But only when I enqueue the css and js.) Then I can load the page /test in non-builder mode and the see the plugin loaded and showing Hello World also. So it works but I get the saving error. I really need to get rid of it.
Any ideas? Thx CC
I tried many template also also used a new generated template using chat gpt. ;D But I tried a lot how to integrate the css and js.