Can’t seem to attach uploaded image to post and set it as thumbnail

You have a variable scope problem. $post_id = wp_insert_post($post_information); function upload_user_file( $file = array() ) { require_once( ABSPATH . ‘wp-admin/includes/admin.php’ ); $file_return = wp_handle_upload( $file, array(‘test_form’ => false ) ); // … You set $post_id outside of your upload_user_file() function but that means that it is unavailable inside the function where you need it for … Read more

Multiple images with Media Uploader on front-end

You can’t have two buttons with the same ID (#upload_image_button) as IDs are supposed to be unique. You should give the buttons a class and give the ID equal to that of the name of the associated input. <input type=”text” size=”36″ name=”image_1″ value=”http://” /> <input id=”image_1″ class=”button upload_image_button” type=”button” value=”Upload Image” /> <input type=”text” size=”36″ … Read more

Show media url immediately after upload in media uploader

Here’s a heinous hack that replaces the title of uploaded images with the url (constructed by chopping the “-150×150” affix from the pinkynail): function wpse156087_admin_footer_media_new_php() { ?> <script type=”text/javascript”> jQuery(document).ready(function() { (function ($) { uploader.bind(‘UploadComplete’, function() { setTimeout(function() { $(‘#media-items .media-item’).each(function () { var img_src = $(‘img’, this).prop(‘src’); if (img_src.indexOf(‘/wp-content/uploads/’) > 0) { $(‘.filename.new .title’, … Read more

Override img class in gallery

You should add !important to your styles in order to override it. Better way to do this is to copy the .img-responsive styles from the Bootstrap CSS file and apply these styles to your desired HTML element instead of adding a class using PHP. img.attachment-large { display: block; max-width: 100%; height: auto; } Or target … Read more

Image thumbnails not available post migration, but still accessible via direct URL – DB issue

Domain change This kind of error may be caused by wrong host name in image urls that are stored in the database. It is necessary to replace strings holding your old domain with new one: http://olddomain.com –> http://newdomain.com In every migtration process I use the following recommended tool: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ Upload it to your WP root … Read more

WooCommerce-like featured gallery

I found a solution to this. I am using the plugin (No UI) Metabox that has this feature by default. This is the code i used to achieve my desired result: add_filter( ‘rwmb_meta_boxes’, ‘prefix_register_meta_boxes’ ); function prefix_register_meta_boxes( $meta_boxes ) { $prefix = ‘rw_’; $meta_boxes[] = array( ‘title’ => ‘Media’, ‘pages’ => array( ‘bestilling’), ‘fields’ => … Read more

How to display / include a specific jpg on a page

To load images from the location you currently have them stored use get_site_url() to generate a path: $a = date(‘md’).”.jpg”; $a = get_site_url(null,’images/’.$a); // var_dump($a); Then use that information to create an img tag. I would recommend loading the images from a theme folder, if this is part of a particular theme. If that is … Read more