Looking to display non-image files in Gallery with logo specific to file type

WordPress has a native function wp_mime_type_icon() in wp-includes/post.php that you can use. Basic example: // $attachment should be a full post object if ( wp_attachment_is_image( $attachment->ID ) ) { echo wp_get_attachment_image( $attachment->ID, array( 480, 900 ), FALSE, array ( ‘class’ => ‘aligncenter’ ) ); } else { echo ‘<img src=”‘ . wp_mime_type_icon( $attachment->post_mime_type ) . … Read more

media_handle_upload weird thing

Look into the first lines of this function: function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( ‘test_form’ => false ) ) { $time = current_time(‘mysql’); if ( $post = get_post($post_id) ) { if ( substr( $post->post_date, 0, 4 ) > 0 ) $time = $post->post_date; } $name = $_FILES[$file_id][‘name’]; $file = wp_handle_upload($_FILES[$file_id], $overrides, … Read more

How to exclude certain widget from showing up on home/front page? [duplicate]

I’ve found the exact solution to my question here: https://wordpress.stackexchange.com/a/17687/92505 Here’s the exact code I used after some modification to make it work on my situation. Add the following code to functions.php where ‘sidebar-1’ is your sidebar ID. ‘recent-posts’ is the name of the widget your want yo hide. 12 is the length of the … Read more

get_terms return errors

As i was mentioning before, it’s a case of your term fetching occuring before the taxonomy has been registered. The init action occurs after the theme’s functions file has been included, so if you’re looking for terms directly in the functions file, you’re doing so before they’ve actually been registered. Here’s a portion of the … Read more

Custom field values in permalink

Here’s how I’d do it. I’m just going to say, I haven’t tested this code at all, so I don’t know if it even works. It’s more of a starting point for you. function jpb_custom_meta_permalink( $link, $post ){ $post_meta = get_post_meta( $post->ID, ‘<insert your meta key here>’, true ); if( empty( $post_meta ) || !is_string( … Read more