Is it possible to set a default thumbnail that will automatically fill in posts that I didn't assign a thumbnail to?
Default Thumbnails
(6 posts) (2 voices)-
Posted 4 months ago #
-
There is no built in functionality for it, but stuff can be added. add this code to functions.php (of a child theme) to add a placeholder for bfthumbs posts:
function bf_thumb_placeholder() { $placeholder = 'http://domain.com/default-thumb.jpg'; ?> <script> jQuery(function($){ $('.thumb.bfthumbs:not(:has(img))').each(function(){ $(this).prepend('<img width="'+($(this).width())+'" src="<?php echo $placeholder; ?>" />'); }); }); </script> <?php } add_action( 'wp_head', 'bf_thumb_placeholder' );Change the $placeholder url to the thumb placeholder url.
Posted 4 months ago # -
Thanks!
Posted 4 months ago # -
here's another solution, using the bfthumbs_content filter:
function bfthumbs_placeholder($thumbPost, $atts) { if ($atts['pholder']) $placeholder = $atts['pholder']; else $placeholder = 'http://domain.com/default-thumb.jpg'; if (!($width = $atts['width'])) $width = '255'; $placeholder = '<img src="'.$placeholder.'" width="'.$width.'" />'; $image = false; if (is_array($thumbPost[0])) { foreach ($thumbPost as $items) if ($items['image']) $image = true; if (!$image) array_unshift($thumbPost, array('image' => $placeholder)); } else if (!$thumbPost['image']) $thumbPost['image'] = $placeholder; return $thumbPost; } add_filter('bfthumbs_content', 'bfthumbs_placeholder', 10, 2);This will only work for bfthumbs, but the jQuery one can be modified to work with the blog thumbs, portfolio template, featured widget etc. The advantage using the filter one is that a pholder parameter can be added to the bfthumbs shortcode with a placeholder image url (can have different placeholder per shortcode).
Posted 4 months ago # -
Okay,
I tried the first solution on the functions.php of the child theme (BFArea) and it doesn't workfunction bf_thumb_placeholder() {
$placeholder = 'http://www.headfonia.com/wp-content/uploads/2012/01/blank_thumb.png'; ?>
<script>
jQuery(function($){
$('.thumb.bfthumbs:not(:has(img))').each(function(){
$(this).prepend('" />');
});
});
</script>
<?php
}
add_action( 'wp_head', 'bf_thumb_placeholder' );Where the default thumbnail is here:
http://www.headfonia.com/wp-content/uploads/2012/01/blank_thumb.pngI also tried the bfthumbs_content filter method (Same thumb file on the placeholder), still no results. Where did I make the mistake?
Posted 4 months ago # -
ok. the code you paste is corrupt, but that is probably because you are not using backticks (see below the send post button).
Both codes only work when you use a bfthumbs shortcode, not anywhere else (not the thumbs in the blog). I have tested that both codes work. If you want the first one to work for the blog/archive/search thumbs it must be modified (the classes are slightly different).
Posted 3 months ago #
Reply
You must log in to post.