/** * Register Assets for front-end * * @used-by Actions: WordPress\'init' */ function register_assets() { wp_register_style('google-fonts', 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700'); wp_register_style('boilerplate-main', boilerplate_get_asset_url('styles/dist/main.css'), ['google-fonts'], ASSET_VERSION, 'all'); wp_register_script('boilerplate-vendors', boilerplate_get_asset_url('scripts/dist/vendors.js'), ['jquery'], ASSET_VERSION, true); wp_register_script('boilerplate-app', boilerplate_get_asset_url('scripts/dist/app.js'), ['boilerplate-vendors'], ASSET_VERSION, true); }
/** * Retrieve the post thumbnail. * * @param mixed[] $args { * @type int $post_id Post ID. Default is the ID of the `$post` global. * @type string|array $size Optional. Registered image size to use, or flat array of height * and width values. Default 'post-thumbnail'. * @type string|array $attr Optional. Query string or array of attributes. Default empty. * } * * @return string Returns a path to the featured image or a placeholder */ function boilerplate_get_featured_image($args = []) { $upload_dir = wp_upload_dir(); $defaults = ['placeholder' => boilerplate_get_asset_url('images/backgrounds/placeholder-' . intval(rand(1, 2)) . '.jpg'), 'size' => 'post-thumbnail', 'attr' => '', 'post_id' => null]; if (is_string($args)) { $args = ['size' => $args]; } else { if (is_int($args)) { $args = ['post_id' => $args]; } else { if (!is_array($args)) { $args = []; } } } $args = wp_parse_args($args, $defaults); $args['post_id'] = null === $args['post_id'] ? get_the_ID() : $args['post_id']; $args['thumb_id'] = get_post_thumbnail_id($args['post_id']); $image = wp_get_attachment_image_src($args['thumb_id'], $args['size'], $args['attr']); if (is_array($image)) { $image = $image[0]; } $path = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $image); if (empty($image) || !file_exists($path)) { $image = $args['placeholder']; } return $image; }
/** * Display the URL for an asset in the 'assets' directory * of the current theme/child theme. * * Returns the {@see get_stylesheet_directory_uri()} value with the * appropriate protocol, and path to the 'assets' directory. * * This function is based on {@see home_url()}. * * @param string $path Optional. Path relative to the current theme/child theme. * @param string $scheme Optional. Scheme to give the home URL context. Accepts * 'http', 'https', or 'relative'. Default null. * @return string Asset URL link with optional path to asset appended. */ function boilerplate_asset_url($path, $scheme = null) { echo boilerplate_get_asset_url($path, $scheme); }