Skip to content

Instantly share code, notes, and snippets.

@jcklpe
Created November 21, 2018 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcklpe/dc885654c93c0d145e2fb876529735fa to your computer and use it in GitHub Desktop.
Save jcklpe/dc885654c93c0d145e2fb876529735fa to your computer and use it in GitHub Desktop.
Easy relative path scss function for wordpress themes
//-FUNCTIONS
//adapted from here: https://css-tricks.com/snippets/sass/simple-asset-helper-functions/
// Base path for assets (fonts, images...),
// should not include trailing slash
$asset-base-path: 'wp-content/themes/{{name of your theme}}/assets' !default;
// Asset URL builder
@function asset($type, $file) {
@return url($asset-base-path + '/' + $type + '/' + $file);
}
// Image asset helper
@function image($file) {
@return asset('images', $file);
}
// Font asset helper
@function font($file) {
@return asset('fonts', $file);
}
//Usage Example
//- FONTS
@font-face {
font-family: 'AllerBold';
src: font('/Aller/AllerBold.woff2') format('woff2'),
font('/Aller/AllerBold.woff') format('woff');
}
.foo {
background-image: image('kittens.png');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment