Created
November 21, 2018 01:25
-
-
Save jcklpe/dc885654c93c0d145e2fb876529735fa to your computer and use it in GitHub Desktop.
Easy relative path scss function for wordpress themes
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
//-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