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.
Related
I doing some quick test by replacing the standard video.png icon at /wp-admin/upload.php with the ready video snapped thumbnail.
So that in future, I can easily know the video is related to what topic by seeing the image, not the video icon....
I test it with quick code, but failed to replace video.png.
Any wordpress expert can give some clue what might go wrong.
$converted_video_attachment_id = wp_insert_attachment($converted_video_attachment, $converted_video_path, $post_id);
add_filter('wp_mime_type_icon', 'change_mime_icon', 10, 3);
$thumb = "https://nationaltoday.com/wp-content/uploads/2020/08/international-cat-day-640x514.jpg";
$mime = "image/jpeg";
apply_filters( 'wp_mime_type_icon', $thumb, $mime, $converted_video_attachment_id );
function change_mime_icon($thumb, $mime = null, $post_id = null){
return $thumb;
}
From the edit button of the video ob_mp4_cc_6331bf30bbd51, I right click get this id 554,
/wp-admin/post.php?post=554&action=edit
So I assign $converted_video_attachment_id = 554 to test.
But the video icon won't change to image display.
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>";
}
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/
I would like to change the logo redirection when clicked. Right now when you click on the logo, the user is redirected to the homepage but I want it to redirect to another site. How do I do this?
I agree with Stu Mileham. Another way to implement what you are asking for would be to use JavaScript / jQuery.
Save the following code to a .js file (eg. pageRedirect.js, let's say placed in a js folder inside your theme's root folder):
(function($) {
$(document).ready(function() {
$('#pageLogo').on( "click", function(event) {
event.preventDefault();
window.location.assign("http://www.google.com/");
});
});
})(jQuery);
To make the previous code work, you would have to select somehow the page logo via jQuery.
On the previous code this is achived via $('#pageLogo') since I have made the assumption that your logo has an id with the value pageLogo.
Of course, to enable your theme to use this pageRedirect.js file, you have to enqueue it by placing the following code to your theme's functions.php file:
/**
* Enqueue pageRedirect script.
*/
function pageRedirect_scripts() {
wp_enqueue_script( 'page-redirect-js', get_template_directory_uri() . '/js/pageRedirect.js', array('jquery'), '20150528', true );
}
add_action( 'wp_enqueue_scripts', 'pageRedirect_scripts' );
Code Explanation:
//-jQuery selects html element with id='pageLogo'
//-when it is clicked, it calls a function in which it passes the event
$('#pageLogo').on( "click", function(event) {
//prevents page from redirecting to homepage
event.preventDefault();
//redirects to your desired webpage
window.location.assign("http://www.google.com/");
});
If you don't have the option to change the link from admin then you will have to edit your theme's header.php file (most likely, depends on how the theme is built though).
Many themes have a tag similar to the following:
<img src="logo.jpg">
You would need to change this to:
<img src="logo.jpg">
I've added the target tag to open the site in a new window, this is my personal preference when re-directing to a different site but it's optional.
Your theme files might look very different to this, it's impossible to know for sure without seeing some code, but this should give you an idea.
Also be aware that your changes could be overwritten by a theme update. This can be avoided by creating a child theme.
https://codex.wordpress.org/Child_Themes
Depends on your theme
Some theme creators gives you the possibility to change the link from admin
Some theme creators just believe that clicking the logo you need to go on homepage - so you need to edit the theme
Depending upon the theme you are using, you can try one of the following options.
Explore the admin options and see if the theme provides a direct way to change the link on the logo.
If not found in admin options, try looking for the code in header.php. Do an inspect element on your logo and see the html code surrounding the logo file, If the code is directly present in header.php, your task is simple. Just change the code to update the URL, instead of reading it from home_url(). Something like <a href="<?php echo home_url();?>"> will need to be replaced with <a href="https://www.example.com">
The other option to look for is get_custom_logo. Some themes get the logo code from this function. You can apply a filter to change the home_url just before this method is called in your theme and then remove filter afterwards. Or else you can copy the code from wordpress and update it with a differently named function say get_custom_link_logo in functions.php then where'ver your theme is using get_custom_logo you can use get_custom_link_logo instead of that.
function get_custom_link_logo ( $blog_id = 0 ) {
$html = "";
$switched_blog = false;
if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) {
switch_to_blog( $blog_id );
$switched_blog = true;
}
$custom_logo_id = get_theme_mod( 'custom_logo' );
// We have a logo. Logo is go.
if ( $custom_logo_id ) {
$custom_logo_attr = array(
'class' => 'custom-logo',
'itemprop' => 'logo',
);
/*
* If the logo alt attribute is empty, get the site title and explicitly
* pass it to the attributes used by wp_get_attachment_image().
*/
$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true );
if ( empty( $image_alt ) ) {
$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' );
}
/*
* If the alt attribute is not empty, there's no need to explicitly pass
* it because wp_get_attachment_image() already adds the alt attribute.
*/
$html = sprintf( '%2$s',
esc_url( "https://www.example.com" ),
wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr )
);
}
// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).
elseif ( is_customize_preview() ) {
$html = sprintf( '<img class="custom-logo"/>',
esc_url( "https://www.example.com" )
);
}
if ( $switched_blog ) {
restore_current_blog();
}
/**
* Filters the custom logo output.
*
* #since 4.5.0
* #since 4.6.0 Added the `$blog_id` parameter.
*
* #param string $html Custom logo HTML output.
* #param int $blog_id ID of the blog to get the custom logo for.
*/
return apply_filters( 'get_custom_logo', $html, $blog_id ); }
This might not cover all the use cases, but you get the idea. Depending upon the theme you'll have a similar solution for your case. The important thing to figure out which case you fall under will be to identify the code where html for your logo is getting added. header.php is a good starting point.
Use this javascript in the header or footer of your theme:
<script>
document.getElementsByClassName("site-logo")[0].getElementsByTagName('a')[0].href="https://www.test.com";
</script>
i am assuming that site-logo is the class name of your LOGO.
I hae created a website and i haev set a blog with featured images but the images dont show full it just shows half of it even if i change it in css it still shows half.
can anyone help me please
Where the image is shown in code:
// has_post_thumbnail() - boolean
get_the_post_thumbnail($id, $size, $attr ) // gets any thumbnail
the_post_thumbnail( $size, $attr ) // for use inside the loop
// demand a custom featured image size on upload for a custom post type.
add_image_size( 'review_type', 245, 245, true);
// call that size
the_post_thumbnail( $size, $attr ) // for use inside the loop
When uploaded in the media library you can choose the upload image size. However WP creates 3 images upon upload and fits one of them into your page. The function above can specify which image is used by "small", "medium", "large".