Creating an effective coming soon page with a countdown is so incredibly versatile, whether you're announcing an upcoming product launch, displaying the remaining time for a discounted offer, releasing a movie trailer, or simply informing visitors that your website is under maintenance.
I think that a useful coming soon page can build anticipation and encourage visitors to return when your product, service, or site is ready. It's important to include meaningful content that captures their attention, as this can help maintain their interest during the waiting period. The content might change depending on the scenario, like updating the countdown for a film release or changing the messaging for a product launch. That’s why it's important to be able to update the page easily without affecting the overall design.
In this tutorial, we’ll focus on using a coming soon page to notify visitors during website maintenance using the MB Views extension from Meta Box.
Video Version
Before Getting Started
I’ll show you how to use custom fields to manage dynamic content like images, messages, and timers. This way, whenever you need to make updates, you can easily replace the content in the fields, and the page will automatically reflect the changes.
Let’s look for the detailed list of tools we need for this practice.
First, it’s the Meta Box core plugin to have a framework to create a settings page and custom fields for the coming soon page content. This plugin is available on wordpress.org.
Next, you may also need some advanced features from Meta Box provided by its extensions. You can install those extensions individually, or use Meta Box AlO to have them all.
These are the extensions you may want.
- MB Settings Page: allows you to create a settings page to input all the information that we want to be on the coming soon page;
- MB Views: helps to create a template for displaying the coming soon page’s content;
- Meta Box Builder: to have a UI on the back end to create custom fields visually.
Besides, you can make the most of some other extensions to have your own field structure that fits your page’s content. They may be Meta Box Tab, Meta Box Conditional Logic, or Meta Box Group, and so on. However, they are just optional.
Let’s start now.
Create a Settings Page
The coming soon page can be a normal page or a settings page as well, and all the content will be included in custom fields. So, I choose to use the settings page for this case.
Go to Meta Box > Settings Pages and create a new one.
The page is still blank now since we haven’t added any fields to it.
Let’s move to the next step.
Create Custom Fields for the Page Content
Instead of directly adding specific content to the page, I'll use custom fields to store all the information.
Go to Custom Fields in Meta Box and create a new field group.
Simply create each field one by one.
For the countdown, I recommend using the Datetime Picker field to store both the date and the exact time of the launch, ensuring precision and creating urgency for upcoming events.
After creating all the fields, move to the Settings tab, set the Location as Settings page, and choose the created settings page to apply the fields to it.
Then, on your settings page, you will see custom fields displayed.
Just input some content to the fields. They will be used to display on the coming soon page later. Note that the Time field is to input the exact date and time when the event takes place. And after that, we’ll use JavaScript to display the countdown.
Get all Content of the Coming Soon Page
Go to Meta Box > Views to create a new template for the coming soon page.
With MB Views, you can add some lines of code to the box, or insert fields by clicking the Insert Field button, then choosing fields on the right sidebar to get data from custom fields.
Since our fields are on a settings page, turn to the Site section to see them.
First, for the image of the coming soon page, insert the corresponding field. You can choose an image size that fits your page style, as well as its output.
Next, to display the message and description, choose the right fields one by one.
For the timer, insert the Time field. And you can choose the right format for it.
Now, go to the Settings section to apply this template for the coming soon page.
For the location of this template, you can choose any page to make it come soon. But in the case the whole website is coming soon, I recommend to set this view as Code type, also use the conditional tag to let every visitor who is not logged in see the coming soon page.
On the frontend, you’ll see the coming soon page information.
Now, all the data is in simple text, so you may need to style it a bit. And also, create the countdown, which is a very useful feature for this page. So, let’s move on to the next step.
Style the Page and Create the Countdown
Include some Elements
In the created template with MB Views, include some div tags, classes, and HTML IDs to make styling easier.
In there:
I created a new attribute, date-time
, to store the value of the Time field, so JavaScript can easily use it for a countdown without changing the code later.
These IDs, as shown in the image below, will be used later in JavaScript to create the countdown.
Particularly:
main-comingsoon
: is simply for the main container that holds all content related to the coming soon page, including the countdown.run_countdown
: wraps all countdown elements.set_day
,set_hours
,set_minutes
, andset_second
: are used to display the corresponding values for days, hours, minutes, and seconds in the countdown.
After including these elements, the page will have the following structure:
Add Styling
In the CSS tab of the view, and add some code for styling the page.
Then, the page displays with a better look already, but the countdown time does not work yet.
Run the Countdown
Back to the template, move to the Javascript tab, then add code as follows.
Let’s go through for more details.
var get_date = document.getElementById("main-comingsoon").getAttribute("data-time");
This line of code gets the value of the data-time
attribute that I created earlier.
var countDownDate = new Date(get_date).getTime();
This one returns a numeric value representing the time for the specified date, calculated in milliseconds.
var countdownfunction = setInterval(function () {
This is to create the setInterval
function that runs every second to take an action.
var now = new Date().getTime();
The line above is to get the current date and time, returning it as a numeric value in milliseconds as well.
var distance = countDownDate - now;
This calculates the remaining time for the countdown by subtracting the current time from the selected time in the Time field.
var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000);
These lines help to calculate the remaining time in days, hours, minutes, and seconds using the Math.floor()
function to round down to the nearest whole number.
After calculating the remaining time, this part below assigns the results to the corresponding HTML IDs. For example, the number of days is set in the element with the set_day
ID, and similarly for hours, minutes, and seconds.
document.getElementById("set_day").innerHTML = days; document.getElementById("set_hours").innerHTML = hours; document.getElementById("set_minutes").innerHTML = minutes; document.getElementById("set_second").innerHTML = seconds;
Finally, this code checks if the timer has finished. If it has, it stops the countdown and hides the coming soon page, allowing users to access the main site. And vice versa.
if (distance < 0) { clearInterval(countdownfunction); document.getElementById("main-comingsoon").remove(); }
From now on, whenever visitors go to my website, they’ll find this page. Once the countdown ends, they’ll be directed to the live website immediately.
Someday, when you want to change the content of this page, including the image, message, or time you want to finish maintenance, simply go back to the settings page, change the data saved in the custom fields.
Then, you will have a new page with fresher content, and the countdown also is automatically working well with the new timestamp.
Last Word
You now have a dynamic coming soon page with a countdown using the MB Views extension from Meta Box. This setup makes it easy to update content anytime without changing the design, keeping visitors engaged until your site or product is ready.
If you've worked with custom 404 pages, the process is quite similar. Both use custom fields created with Meta Box to store and update information effortlessly.
Other series you might be interested in
- Author Bio
- Better 404 Page
- Blogs for Developers
- Building a Simple Listing Website with Filters
- Building an Event Website
- Building Forms with MB Frontend Submission
- Coding
- Create a Chronological Timeline
- Custom Fields Fundamentals
- Design Patterns
- Displaying Posts with Filters
- Download and Preview Buttons
- Dynamic Banners
- FAQs Page
- Featured Products
- Full Site Editing
- Google Fonts
- Gutenberg
- Hotel Booking
- Latest Products
- Logo Carousel
- MB Views Applications
- Meta Box Builder Applications
- Meta Box Group Applications
- Most Viewed Posts
- Opening Hours
- OTA Website
- Product Page
- Product Variations
- Querying and Showing Posts by Custom Fields
- Recipe
- Restaurant Menus
- SEO Analysis
- Simple LMS
- Speed Up Website
- Taxonomy Thumbnails
- Team Members
- User Profile
- Video Gallery