New answers tagged

1

Your problem can be solved using CSS and a small filter. Your proposed solution is not viable. You can check the attributes of some blocks but changing those attributes will not re-render the block if its HTML was generated by javascript. This means the majority of the standard blocks cannot be modified this way, and modifying the class attribute will not ...


0

If you have the attachment ID, you can just use get_the_date(): <?php echo get_the_date( '', $attachment_id ); ?> If you leave the first argument blank, e.g. '', then it will use the date format from settings. If you don't want that, then provide a PHP date format.


1

This code worked for me: function alterImageSRC($image, $attachment_id, $size, $icon){ if ( is_front_page() ) { return $image; } $image[0] = 'http://newimagesrc.com/myimage.jpg'; return $image; } add_filter('wp_get_attachment_image_src', 'alterImageSRC', 10, 4);


0

The true WordPress way would be to use provided function get_image_tag() to obtain image tag, providing id and alt arguments to the function. Other answers already explain how to get alt attribute. It also takes care of srcset and sizes attributes, which you should otherwise provide manually using wp_get_attachment_image_srcset, in order to have modern ...


0

i fix this with a new shortcode that generates the entire tag. Like this: function generate_image_tag($atts) { $atts = shortcode_atts( array( 'img' => '', 'title' => '', 'theme_url' => get_bloginfo('template_url'), ), $atts ); //File path details $file_info = pathinfo($atts['img']); $file_dir = $...


0

Please insert the script below to function.php in your theme: function custom_myme_types($mime_types){ $mime_types['images'] = "png/jpg"; return $mime_types; } add_filter('upload_mimes', 'custom_myme_types', 1, 1);


1

Your conditional is in trouble. get_the_category() returns an object, use foreach to find the specific category. In addition, you assigned a value to the $categories variable, to compare you must use the comparison operators ( Ex: == or === ) I refactored the code and adapted it to your case, I hope it helps. add_action( 'save_post', 'wp_force_featured_image'...


0

If you're building a custom theme and you just want to have some fallback images, an easier approach might be to do something like this in your template: <?php if (has_post_thumbnail()) { the_post_thumbnail(); } else if (in_category('news') { echo wp_get_attachment_image('3135'); } else if (in_category('bi') { echo wp_get_attachment_image('3138'); } ...


0

On :hover you should change the svg-image, not the color. The second image is a copy with a different color. For example, if your image is shown in the background, you can change the style in this way: .sidebar-btn-icon:hover { background-image: url(button_image_red.svg'); }


0

Just use the the_post_thumbnail() function. It creates the image tag, adds srcset for you, and supports native lazy loading: the_post_thumbnail( 'medium', [ 'class' => 'productimage' ] );


1

<img src="<?php echo get_template_directory_uri().'/images/sample.png'; ?>"> Try this. It should work. You have to concatenate the results from get_template_directory_uri() and your images directory in echo.


2

TRY THIS,IT MAY HELPFUL Converted to CSV file. uploaded to root folder having column structure as given which contains attachment image ID and alter text run this code for one time only $row = 1; if( ($handle = fopen ( "Book1.csv", "r" )) !== FALSE ) { while ( ($data = fgetcsv ( $handle, 1000, "," )) !== FALSE ) { ...


Top 50 recent answers are included