Validate Uploaded Image using WordPress’ Built-in Functions?

All of the code in your question can be replaced with: require_once( ABSPATH . ‘wp-admin/includes/image.php’ ); require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); require_once( ABSPATH . ‘wp-admin/includes/media.php’ ); if ( $_FILES ) { foreach ($_FILES as $file => $array) { $image_post_id = media_handler_upload( $file ); if ( is_wp_error( $image_post_id ) ) { $error .= $image_post_id->get_error_message(); } else … Read more

How to get to a specific position in wp_query?

I think instead of using PHP rand you’re better off limiting ( if you need to ) using posts_per_page and then getting a random set using orderby => ‘rand’. Full List of Ordering Parameters So if I were to edit your query it would look like this: $args = array( ‘post_type’ => ‘attachment’, ‘meta_key’ => … Read more

Deregister and Dequeue Stylesheets From a Plugin and Enqueue a Child’s Stylesheet/s

As kaiser noted, you probably need a higher priority. add_action( ‘wp_enqueue_scripts’, ‘load_alta_styles’, 20 ); But if not, you can use wp_style_is to check and see after you do things if they are as expected. e.g. you might try: if ( wp_style_is( ‘wp_listings_single’, ‘enqueued’ ) ) { wp_dequeue_style( ‘wp_listings_single’ ); echo ‘<p>Seems to have been dequeued</p>’; … Read more

Web scraping using transients

Try something like this, which would save in transient for 12 hours. Let me know if anything does not make sense. <?php $value = get_transient( ‘value’ ); if ( false === $value ) { $output = “”; $html = file_get_contents(‘http://www.example.com’); $doc = new DOMDocument(); libxml_use_internal_errors(TRUE); // disable libxml errors if(!empty($html)) { $doc->loadHTML($html); libxml_clear_errors(); $xpath = … Read more

Excerpt unwanted text “”

This little function I created to see what happends when… Outcome here was showing the excerpt as wished when filled out in backend and if left empty it keeps blank. I have no idea why you have filter it that way but that is the way you wish I assume. add_filter( ‘get_the_excerpt’, ‘if_excerpt_left_empty_show_this’ ); function … Read more

How to only show page id as body class?

Honestly, it’s source code. The only people who see it are you and other developers. Anybody casually visiting your website will never know or understand this stuff so really there’s no harm keeping it there. Buttttt… if you want to get rid of it you could filter body_class: function custom_body_class( $classes ) { global $post; … Read more

Placing raw HTML inside a WordPress shortcode

For the sake of having @Milo’s comment as an answer. Your code works as it should, it is just not possible to “write” HTML in the visual editor also in shortcodes. Shorcodes are not treated differently then any other text. If you want formatted HTML in your shortcode you just need to use the normal … Read more