• I tried to write a very basic plugin, taking information from the net. For the moment I am yet to add any proper code, and first I was checking if things were working. I found its not working, both of the below functions failed to load.

    Both eo.php (the file with the following codes) and eos.css are in the same folder : wp-content/plugins/eo/

    if( !function_exists('eo')){
        	function eo($text) {
        		$text = str_replace('Test', 'Best', $text);
        		return $text;
        	}
        	add_filter('the_content', 'eo');
        }
    
        if( !function_exists('eos')){
        	function eos( ){
        		wp_register_style( 'eo', plugins_url('eo/eo.css', __DIR__) );
        		wp_enqueue_style( 'eo' );
        	}
        	add_action( 'wp_enqueue_scripts', 'eos' );
        }

    And then question, can I load a js file along with like this ?

    if( !function_exists('eos')){
            	function eos( ){
            		wp_register_style( 'eo', plugins_url('eo/eo.css', __DIR__) );
        			wp_register_script( 'eojs', plugins_url('eo/eo.js', __DIR__) );
            		wp_enqueue_script( 'eo' );
        			wp_enqueue_script( 'eojs' );
            	}
            	add_action( 'wp_enqueue_scripts', 'eos' );
        }

    Any help will be welcomed
    Thanks a lot ??

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Your main plugin file must have the standard header or else WP will not recognize your plugin.

    Your register and enqueue style and script usage looks OK to me. Once you activate your plugin successfully, you can check the head section of the resulting page source and see that the file references are indeed there.

Viewing 1 replies (of 1 total)
  • The topic ‘Tried to write a very basic plugin, help please plugin gurus !’ is closed to new replies.