How to programatically toggle the media setting “Organize my uploads into month- and year-based folders”?

The (database) option name for that setting is uploads_use_yearmonth_folders, so you can use update_option() to programmatically change the setting’s value: // 1 to enable the “checked” state update_option( ‘uploads_use_yearmonth_folders’, 1 ); You can also use a filter hook such as option_<name>: add_filter( ‘option_uploads_use_yearmonth_folders’, function ( $value ) { return 1; // 1 = checked } … Read more

Automatically Insert alt attribute above image has h2

I find the solution using this How to change the markup WordPress inserts for post images My final code is: add_filter( ‘image_send_to_editor’, ‘add_custom_data_attribute_send_to_editor’, 10, 8 ); function add_custom_data_attribute_send_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ){ if( $id > 0 ){ $post = get_post( $id ); $html = str_replace( “<img src”, “<h2>$alt</h2><img src”, $html … Read more

Move media files from the root to date folder structure

Normally, WordPress stores all your images and other media files in the /wp-content/uploads/ folder. To keep it structured, all files are stored in folders organized by year and month. The problem you will run into with reorganizing them is that links to the files in posts and pages will not update if you are simply … Read more

WordPress media upload issue could not insert attachment into the database

Try the following solutins: First of all check your WP database size and check whether the size is full according to your hosting provider’s requirement/rule. Second option, add this line into your wp-config.php: define(‘WP_MEMORY_LIMIT’, ‘256M’); Also if you have access to php.ini (or php[version number].ini) file on your server, try to add this line: memory_limit … Read more

Flat media folder vs multiple directories

I recently took over a website that uses a flat media folder in the site root. Is there a benefit to that over using the standard WordPress media folder structure of uploads/year/month/file? Not particularly, mostly preference. Some people might do it thinking it enhances SEO, but I’ve seen no evidence to support that claim. My … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)