Randomise upload filenames (or another solution to hide the original image URL from theft?)

Where am I going wrong? Actually, your code is just fine. Except that I would simply use wp_generate_password() to generate the random string. 🙂 WordPress will still think that the scaled version is called painting-scaled.jpg , etc. Resulting in broken images. Yes, that’s correct. Images are stored as posts of the attachment type in the … Read more

Custom HTML in specific category single page and its descendant categories

A few changes to your code: Changed the action hook to wp_head. Removed the false ‘pluggable’ wrapping of your function. if ( ! function_exists( ‘post_is_in_descendant_category’ ) ) { function post_is_in_descendant_category( $cats, $_post = null ) { foreach ( (array) $cats as $cat ) { // get_term_children() accepts integer ID only $descendants = get_term_children( (int) $cat, … Read more

wp_get_attachment_image function size argument not working if I also add a custom class

Just as Tom mentioned in the comments above. The fourth parameter of wp_get_attachment_image sets the value, not adds to it so it will override the auto generated class. If you need the size class and your custom class you can simply add both of them manually like so… echo wp_get_attachment_image( $image_id, ‘image-size’, ”, [ ‘class’ … Read more

Enqueue scripts not working with if is page conditional tag in functions.php

Try doing in the opposite way. Add_action can always be active, and add the if statement into the function. Like this: add_action(‘wp_enqueue_scripts’, ‘insert_mapsvg_scripts’); function insert_mapsvg_scripts() { if( is_page( 37629 ) ) { wp_enqueue_style( ‘mapsvg_css’, site_url(‘/mapsvg/css/mapsvg.css’) ); wp_enqueue_style( ‘nanoscroller_css’, site_url(‘/mapsvg/css/nanoscroller.css’) ); wp_enqueue_script( ‘mousewheel_js’, site_url(‘/mapsvg/js/jquery.mousewheel.min.js’), array(‘jquery’), ”, true ); wp_enqueue_script( ‘nanoscroller_js’, site_url(‘/mapsvg/js/jquery.nanoscroller.min.js’), array(‘jquery’), ”, true ); wp_enqueue_script( … Read more

add_query_arg not working

If you take a look where the category_link hook is defined in category-template.php you’ll see this particular hook passes on two variables. The second variable is the category ID, but your callback function treats that second incoming variable as a query object. Simply put, you’re looking for a query_vars property/key that does not and cannot … Read more

post to subcategory and parent in wp_insert_post

The problem is, you can’t make an array like that in PHP. Trying to cast a string that contains a comma separated list as an array just produces an array with a single value–your comma separated string. You want to use php’s explode function to create the array. It takes a string an splits it … Read more

Event Calendar using insert_post_data after save_post and insert_post after post_transition draft_to_schedule

Hi @user2271: I recently had to resolve a situation for an Event custom post type where I could not get WordPress to let me save a future date. I wasn’t trying to be as complex as yours but the follow code resolved my issue, maybe you can use it to resolve yours: add_action(‘admin_init’, ‘yoursite_admin_init’); static … Read more