Tag Info

New answers tagged

1

You could do like this: function image_tag_class($class) { $class .= ' my-custom-class'; return $class; } add_filter('get_image_tag_class', 'image_tag_class' ); in case you wanna know more about actions and hooks. Difference Between Filter and Action Hooks? add_filter add_action


0

I've Discovered that you can use the add_image_size function to achieve this. Function Reference/add image size


1

Just as an addition, as an improvement to account for different image sizes, I would do: $file_name = pathinfo( $file, PATHINFO_FILENAME ); $file_extension = '.' . pathinfo( $file, PATHINFO_EXTENSION ); Instead having a combined value for $file. And change the SQL preparation to: $prepared_sql = $wpdb->prepare( $sql, $id, ...


3

Second pass. Known issues: Needs caching (and the cache needs to be tidied up where possible) Post types are hard-coded Which post statuses are we interested in? Here's the function: /** * Given an attachment ID, searches for any post with that attachment used * as a featured image, or if it is present in the content of the post. * (Note above known ...


0

You can use a image_send_to_editor filter hook to achieve what you want. <?php add_filter( 'image_send_to_editor', 'imagehtmlchange', 10, 8); function imagehtmlchange($html, $id, $caption, $title, $align, $url, $size, $alt) { // your banny wrote - put your code here return $html; } ?>


0

Attachments should always use the absolute filesystem path. Also to change the Content-Type of the email you should use the wp_mail_content_type filter. <?php function my_custom_email() { $to = 'my@email.com'; $subject = 'WordPress wp_mail'; $message = ' <html> <body> <table rules="all" style="border-color: ...


0

It's more a programming question, but try this: $post = get_post( get_post_thumbnail_id() ); if ( !isset( $post->post_title ) ) { echo 'Sorry no title'; } else { echo $post->post_title; }


0

Use if statements. if($caption = get_post(get_post_thumbnail_id())->post_excerpt){ echo $caption; }else{ //echo something else }


3

You can use get_attached_file() to: Retrieve attached file path based on attachment ID. And get_post_thumbnail_id() to determine the post thumbnail of the current post, or any post if you set the $post_id parameter. Exemplary usage: $bytes = filesize( get_attached_file( get_post_thumbnail_id() ) ); Use size_format() to ...



Top 50 recent answers are included