Where do I put this snippet?
You can either copy the code to your theme functions.php file, or as explained here at the bottom https://github.com/simpliko/wpadverts-snippets download the snippet to your computer and then install as a plugin.
Note that aside of copying the code you will also need to customize it to only limit the max upload size, so in your case the limit_file_upload() function would look like this
function limit_file_uploads( $form ) {
if( $form['name'] != "advert" ) {
return $form;
}
foreach( $form["field"] as $key => $field ) {
if( $field["name"] != "gallery" ) {
continue;
}
$form["field"][$key]["validator"][] = array(
"name" => "upload_size",
"params" => array(
"min_size" => null, // minimum file size
"max_size" => "4MB" // maximum file size
)
);
}
return $form;
}
Hi Greg, I have tried this both ways – as a plug-in and in the functions.php file but I can still upload images larger than the max size of 4MB. Is there somethings I am missing?
Thanks,
Julie
Hi, it is possible your server or PHP has a lower limit (usually the file upload limit in PHP is set to 2MB).
You can ask your server support what are the limits set on file uploads and if they are around 2MB if they can increase them for you.