Created
May 8, 2015 14:31
-
-
Save ihorvorotnov/9c5b46e8ec57b33ea771 to your computer and use it in GitHub Desktop.
Proper linking in WordPress theme templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* URLs | |
*/ | |
echo home_url( 'contact' ); | |
echo network_home_url( 'contact' ); | |
/** | |
* Static theme files | |
*/ | |
?> | |
<img src="<?php echo get_template_directory_uri(); ?>/images/example.jpg" alt="Example"?> | |
<?php | |
/** | |
* Scripts and styles | |
*/ | |
wp_enqueue_style( | |
'prefix-css-example', | |
get_template_directory_uri() . '/css/example.css', | |
array(), | |
NULL | |
); | |
if ( is_front_page() ) : | |
wp_enqueue_style( | |
'prefix-css-example', | |
get_template_directory_uri() . '/css/example.css', | |
array(), | |
NULL | |
); | |
endif; | |
/** | |
* Loading templates | |
*/ | |
get_template_part( 'path/slug', 'name' ); | |
/** | |
* Passing variables to the template - require() does not make the scope available | |
* but it extracts all the WP_Query vars, so we can cheat a bit | |
*/ | |
set_query_var( 'my_var', $my_var ); | |
get_template_part( 'path/slug', 'name' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment