wordpress add custom css file

Being experience php developer there are several ways (I mean by hook or by crook 😉 ) we can do this, but from coding standard and best practise od wordpress add custom css file is as follows.

Step 1: Create style.css file inside “phptechi” plug-in folder.
Step 2: Now copy following code into plug-in file and you are done.

$siteurl = get_option('siteurl');
define('SRV_FOLDER', dirname(plugin_basename(__FILE__)));
define('SRV_URL', $siteurl.'/wp-content/plugins/' . SRV_FOLDER);
define('SRV_FILE_PATH', dirname(__FILE__));
add_action('wp_print_styles', 'add_srv_stylesheet');
function add_srv_stylesheet()
{
	$newStyleUrl = SRV_URL . '/style.css';
	$newStyleFile = SRV_FILE_PATH . '/style.css';
	if ( file_exists($newStyleFile) )
	{
		wp_register_style('newStyleSheets', $newStyleUrl);
		wp_enqueue_style( 'newStyleSheets');
	}
}
Share this nice post:

Leave a Reply

Your email address will not be published. Required fields are marked *