This worked so well and I have not found a similar post. I needed to block weekends and past dates on a datepicker for a registration form. I happen to be using Ninja Forms, which uses the datepicker built into WordPress. I added the following code to the selected page:
jQuery(function ($) {
// 1 = monday, 2 = tuesday, 3 = wednesday, 4 = thursday,
// 5=friday, 6 = saturday, 0=sunday
var daysToDisable = [0, 6];
$('#ninja_forms_field_69').datepicker({
minDate:0,
beforeShowDay: disableSpecificWeekDays
});
function disableSpecificWeekDays(date) {
var day = date.getDay();
for (i = 0; i
if ($.inArray(day, daysToDisable) != -1) {
return [false];
}
}
return [true];
}
});
You’ll need to replace the variable #ninja_forms_field_69
with the field name from your own website.
The CSS & Javascript Toolbox plugin can be used to add code to a selected page, post, or category.