css - how to link wp tamplate to different stylesheet -
i trying have own stylesheet linked custom page inside theme on wordpress. im using code on header.php
/my-own-styles.css" />
there 2 changes in code made: 'my-template.php' , 'my-own-styles.css' nothing other that. (do need change 'template_directory' too?)
inside theme directory have 'my-own-styles.css' doesn't seem it.
also need .js file have put in same directory wouldnt work..
please help!
in wordpress, need hook javascript , css includes onto wp_enqueue_scripts action, , tell wordpress load them using wp_enqueue_style , wp_enqueue_script functions.
in functions.php file, or other file loaded prior template file (say plugin example), add this:
add_action('wp_enqueue_scripts' , 'enqueue_my_scripts_and_styles'); function enqueue_my_scripts_and_styles() { wp_register_style('my-own-styles.css',home_url('/').'wp-content/themes/**yourthemename**/my-own-style.css'); wp_enqueue_style('my-own-styles.css'); wp_register_script('my-own-js.js',home_url('/').'wp-content/themes/**yourthemename**/my-own-js.js'); wp_enqueue_script('my-own-js.js'); }
there better ways create path file, wanted provide example more obvious. best practices, use get_template_directory_uri() http://codex.wordpress.org/function_reference/get_template_directory_uri
Comments
Post a Comment