How to show multiple featured image in WordPress? - wordpress

I used this dynamic featured image plugin of WP, when I using this plugin it shows all the images what I uploaded.
But I just want to view only one image in this array.
I try this, but doesn't work:
if( class_exists('Dynamic_Featured_Image') ) {
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images( );
//print_r($featured_images);
//You can now loop through the image to display them as required
foreach($featured_images as $featured_image) {
echo "<img src='".$featured_image[1]['full']."'></a>";
}
}

Multiple Featured wordpress plugin
You have to add this plugin

Don't use a foreach loop, just grab the image using the array index you want:
if( class_exists('Dynamic_Featured_Image') ) {
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images( );
//print_r($featured_images);
//you don't need to loop through anything, just use the array index
echo "<img src='".$featured_images[1]['full']."'></a>";
}

Related

How to display color attribute thumbnail on woocommerce product archive loop?

I found this code and is displaying the name of the attribute, anyone can help me modify the code so it displays the thumbnail,
Thank you!
add_action('woocommerce_shop_loop_item_title', 'wh_insertAfterShopProductTitle', 12);
function wh_insertAfterShopProductTitle()
{
global $product;
$abv = $product->get_attribute('culoare');
if (empty($abv))
return;
echo __($abv);
}
You can query everything about your products. It's best to have a look here: WooCommerce get product details
add_action('woocommerce_shop_loop_item_title', 'wh_insertAfterShopProductTitle', 12);
function wh_insertAfterShopProductTitle()
{
global $product;
$image = $product->get_image();
echo __($image);
}

How to hide advanced custom fields(ACF) in the WP-admin UI?

Check the screenshot below; all I want to do is to hide certain ACF fields for custom users in the wordpress backend.
As of ACF 5.0.0 there is an easier way to do this without having to output CSS. If you use the acf/prepare_field hook and return false the field will not render.
<?php
function so37111468_hide_field( $field ) {
// hide the field if the current user is not able to save options within the admin
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
return $field;
}
add_filter( 'acf/prepare_field/key=MYFIELDKEY', 'so37111468_hide_field' );
?>
The documentation for that filter can be found here: https://www.advancedcustomfields.com/resources/acf-prepare_field/
If you mean to hide it with CSS, then you should insert custom CSS to admin footer area.
For example, you can add such kind of code to your theme's functions.php file:
add_action('admin_footer', 'my_admin_hide_cf');
function my_admin_hide_cf() {
$u=wp_get_current_user();
$user_roles = $u->roles;
if ($user_roles[0]=='CUSTOM_USER_ROLE_NAME'){
echo '
<style>
#acf-FIELD_SLUG_HERE {display:none}
</style>';
}
}
And of course you should replace FIELD_SLUG_HERE and CUSTOM_USER_ROLE_NAME values with correct ones.
F.e. #acf-FIELD_SLUG_HERE can be #acf-url, CUSTOM_USER_ROLE_NAME can be "contributor".

Set default image for woocommerce products

In my project I have many products whose image is not available till now. So I want to show custom image for those products who don't have image.
Is there a way to set default image for products (in case if product don't have image).
I solved it by adding following code in functions.php file
add_action( 'init', 'custom_fix_thumbnail' );
function custom_fix_thumbnail() {
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
$src = $uploads . '/2012/07/thumb1.jpg';
return $src;
}
}
NOTE : Do not type complete url of image. Instead of complete url, use only short url as shown in code.
Original Post
TLDR;
You need to upload an image via default Wordpress Media uploader, then copy its URL (or just ID) and paste it to "WooCommerce->Settings->Products->Placeholder image"
Found an answer here: https://www.iqcomputing.com/support/articles/changing-the-woocommerce-default-image/

Customize wordpress oEmbedd (soundcloud)

I am using Wordpress 4.3.1 and I noticed that it used oEmbed to automatically embed my tracks from soundcloud.
This is awesome! Except, I have no control over how the widget is displayed.
First of all I would like to display the "Classic Embed" without the artwork.
Secondly I want the widget to be wider.
How can I achieve this without editing the shortcode for each post in my wordpress page?
You can add a filter to change the way the oEmbed code is displayed. Here is something to get you started:
// this function is called on all urls surrounded by the WordPress embed shortcode.
// i.e.: [embed]https://soundcloud.com/gratefuldead/grateful-dead-box-of-rain[/embed]
function my_embed_options( $code ) {
// look for SoundCloud link:
if( strpos( $code, 'soundcloud.com') !== false ) {
$code = str_replace( 'show_artwork=true', 'show_artwork=false', $code );
}
return $code;
}
add_filter( 'embed_oembed_html', 'my_embed_options' );
You can find full parameter list for the SoundCloud player here.

Dynamic_Featured_Image with theme added image crop

Im using the plugin "Dynamic_Featured_Image" for wordpress. I can get the image to show all the default image sizes (full/medium/thumb), but I want it to use a custom added one in my theme.
<?php
if( class_exists('Dynamic_Featured_Image') )
{
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images();
$i = 0;
foreach ($featured_images as $row=>$innerArray)
{
$id = $featured_images[$i]['attachment_id'];
$mediumSizedImage = $dynamic_featured_image->get_image_url($id,'conferance');
$caption = $dynamic_featured_image->get_image_caption( $mediumSizedImage );
echo " <li><img src=\"".$mediumSizedImage."\" alt=\"".$caption."\"><div class=\"captionText\">".$caption." </div></li>";
$i++;
}
}
?>
And the themesupported thumb is:
add_theme_support( 'post-thumbnails' );
add_image_size( 'conferance', 570, 335, true );
But when I fetch the image it still comes in the full (original size). Any clues why?
Your code is working as expected. Looks like you added the new image size conferance after uploading the images. WordPress doesn't regenerate the newly registered size, it only applies it to the future uploads. Please refer this thread.

Resources