Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
April 16, 2014 at 4:48 pm #252194
i use a popular retina.js function and try to use it with enfol – but the retina.js is not loaded.
i think its a template path problem.function retina_support_enqueue_scripts() { wp_enqueue_script( 'retina_js', get_template_directory_uri() . '/js/retina.js', '', '', true ); }
if i use
get_template_directory_uri()
– it tries to load the js from the parent theme.
what is the correct template path for enfold child theme?April 17, 2014 at 9:49 am #252540Hey basmati!
Please use this on functions.php:
if(!is_admin()) { add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 100); } function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); wp_enqueue_script( 'retina_js', $child_theme_url.'/js/retina.js', '', '', true ); }
Best regards,
IsmaelApril 18, 2014 at 4:52 pm #253234thanks to the code ninjas @ kriesi.at = excellent support guys!
THANKS!But it does not seem to work on post thumbs – i don’t know why …?
For all searching people: use this script in functions.php – with your extension:
// Enqueueing retina.js if(!is_admin()) { add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 100); } function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); wp_enqueue_script( 'retina_js', $child_theme_url.'/js/retina.js', '', '', true ); } add_filter( 'wp_generate_attachment_metadata', 'retina_support_attachment_meta', 10, 2 ); /** * Retina images * * This function is attached to the 'wp_generate_attachment_metadata' filter hook. */ function retina_support_attachment_meta( $metadata, $attachment_id ) { foreach ( $metadata as $key => $value ) { if ( is_array( $value ) ) { foreach ( $value as $image => $attr ) { if ( is_array( $attr ) ) retina_support_create_images( get_attached_file( $attachment_id ), $attr['width'], $attr['height'], true ); } } } return $metadata; } /** * Create retina-ready images * * Referenced via retina_support_attachment_meta(). */ function retina_support_create_images( $file, $width, $height, $crop = false ) { if ( $width || $height ) { $resized_file = wp_get_image_editor( $file ); if ( ! is_wp_error( $resized_file ) ) { $filename = $resized_file->generate_filename( $width . 'x' . $height . '@2x' ); $resized_file->resize( $width * 2, $height * 2, $crop ); $resized_file->save( $filename ); $info = $resized_file->get_size(); return array( 'file' => wp_basename( $filename ), 'width' => $info['width'], 'height' => $info['height'], ); } } return false; } add_filter( 'delete_attachment', 'delete_retina_support_images' ); /** * Retina Bilder loeschen * */ function delete_retina_support_images( $attachment_id ) { $meta = wp_get_attachment_metadata( $attachment_id ); $upload_dir = wp_upload_dir(); $path = pathinfo( $meta['file'] ); foreach ( $meta as $key => $value ) { if ( 'sizes' === $key ) { foreach ( $value as $sizes => $size ) { $original_filename = $upload_dir['basedir'] . '/' . $path['dirname'] . '/' . $size['file']; $retina_filename = substr_replace( $original_filename, '@2x.', strrpos( $original_filename, '.' ), strlen( '.' ) ); if ( file_exists( $retina_filename ) ) unlink( $retina_filename ); } } } } // FUNCTIONS END RETINA SCRIPT
- This reply was modified 10 years, 7 months ago by basmati.
April 19, 2014 at 4:20 am #253411 -
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- The topic ‘retina.js use in child theme template path’ is closed to new replies.