Pull Random Attachments With Pagination

Your since83_pagination() function is assuming the main query– $wp_query— but you are needing to paginate something very different. You need to be paginating the results in $attachments which you are retrieving with get_children(). That was my guess as soon as I saw this question. You are going to need to rethink this. There are two … Read more

Some images not found 404 in localhost

Changing the home and siteurl in your wp_options table is not enough unfortunately. You will still have your post content with your non-localhost URL (http://domain.com) causing your website to not display properly on your localhost. Once you’ve downloaded and imported your database to your localhost. Follow these steps: Go and download Interconnect IT’s Database Search … Read more

Disallow img tag in comments?

You can strip images on display pretty easily. add_filter( ‘comment_text’, function($comment) { $allowed_html = array( ‘a’ => array( ‘href’ => array(), ‘title’ => array() ), ‘br’ => array(), ’em’ => array(), ‘strong’ => array() ); return wp_kses($comment, $allowed_html); } ); That will strip any tags not listed in the provided array. To specifically strip images … Read more

If Media Type .GIF

I’m not quite sure you’re using the wp_check_filetype() correctly. I just successfully tried the following to determine if the post thumbnail ext was jpg or not: $url = wp_get_attachment_url( get_post_thumbnail_id( ) ); $filetype = wp_check_filetype($url); if ($filetype[ext] == ‘jpg’) { echo ‘this is gif’; } else { echo ‘this aint gif’; } You probably know … Read more

Removing height and width from images with a caption

Here is another possibility, it alters the image markup when you select an image to add to your content in the editor add_filter( ‘image_send_to_editor’, ‘remove_img_attribute’, 10, 8 ); function remove_img_attribute( $html, $id, $caption, $title, $align, $url, $size, $alt ) { $imagetpl=”<figure> <a href=”https://wordpress.stackexchange.com/questions/129666/%s” title=”https://wordpress.stackexchange.com/questions/129666/%s”><img src=”https://wordpress.stackexchange.com/questions/129666/%s” alt=”https://wordpress.stackexchange.com/questions/129666/%s” class=”img-responsive %s” /></a> %s </figure>”; $figcaption = (!empty($caption)) ? … Read more

Add an attribute to attachments

This can be done with two filters, attachment_fields_to_edit and attachment_fields_to_save, which do exactly what their names suggest. Let’s say you wan to add a source field. First, generate the field and fill it with its current value if that exists: function wpse133608_add_attachment_location_field( $form_fields, $post ) { $field_value = get_post_meta( $post->ID, ‘source’, true ); $form_fields[‘source’] = … Read more

Site migration – some images not displaying in Media Library

I highly recommend updating all of your URLS. This can be done either with a word press plugin such as Velet Blues Update URLS Or via your SQL database: UPDATE wp_posts set post_content=REPLACE(post_content, ‘www.live.com/’, ‘www.test.com/’); note* images are uploadeded as posts in your database.* ( wp_posts table with a post_type of “attachment”. )

How to remove p tags around img and iframe tags in the acf wysiwyg field

Ok if you want to strip the p tags for img’s and iframe’s for advanced custom fields you have to exchange the_content with acf_the_content . The code looks that way: function filter_ptags_on_images($content) { $content = preg_replace(‘/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU’, ‘\1\2\3’, $content); return preg_replace(‘/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU’, ‘\1’, $content); } add_filter(‘acf_the_content’, ‘filter_ptags_on_images’);