OhhMuaOhhMua
  • Home
  • WordPress
    • Solutions & Troubleshooting
    • Installation & Setup
    • Themes & Plugins
    • Security
  • Tools
    • veo3 prompt generator
  • Our Team
  • Hosting
    • Best Web Hosting
    • Free Web Hosting
    • VPS Hosting
Reading: Share a countdown button to display a password in WordPress
Notification Show More
OhhMuaOhhMua
  • WordPress
  • Entry-level Builds
  • High-end Builds
  • Mid-range Builds
  • Hardware Tips
  • Software Tips
Search
  • Home
  • WordPress
    • Installation & Setup
    • Security
    • Solutions & Troubleshooting
    • Themes & Plugins
  • Tools
    • veo3 prompt generator
  • Our Team
    • Hosting
Follow US
Copyright © 2024 ohhmua. All rights reserved.
OhhMua > Blog > WordPress > Solutions & Troubleshooting > Share a countdown button to display a password in WordPress
Solutions & Troubleshooting

Share a countdown button to display a password in WordPress

Admin (Nghia Vo)
Last updated: September 11, 2024 4:09 pm
Admin (Nghia Vo)
Share
4 Min Read
Share a countdown button to display a password in WordPress
Share a countdown button to display a password in WordPress
SHARE
Contents
Countdown to Display PasswordExample:

When we have a password or a certain string of characters we want to share with others but don’t want to display it immediately, instead requiring the user to wait for a set amount of time after clicking the “show password” button, the code below will help you achieve that.

Share a countdown button to display a password in WordPress
Share a countdown button to display a password in WordPress

The main purpose of this is to increase the amount of time users stay on your site, which is beneficial for SEO and is a common practice on many websites.

Countdown to Display Password

First, you only need to paste the following code into wp-content/themes/{YOUR-THEME}/functions.php.

/*
 * Countdown to display password
 * Usage: [pass_countdown code="1234"]
 * Author: ohhmua.com
 * */
add_shortcode('pass_countdown', 'devvn_passvideo_button_countdown_func');
function devvn_passvideo_button_countdown_func($atts)
{
    $atts = shortcode_atts(array(
        'time' => 10,
        'code' => '',
        'before_code' => '',
        'title' => 'Click here to get the security code',
        'mess' => 'The security code will be displayed in %s seconds',
    ), $atts, 'button_countdown');
    $time = isset($atts['time']) ? intval($atts['time']) : 10;
    $code = isset($atts['code']) ? sanitize_text_field($atts['code']) : '';
    $title = isset($atts['title']) ? sanitize_text_field($atts['title']) : '';
    $mess = isset($atts['mess']) ? sanitize_text_field($atts['mess']) : '';
    $before_code = isset($atts['before_code']) ? sanitize_text_field($atts['before_code']) : '';
    ob_start();
    ?>
    <span data-counter="<?php echo $time;?>" data-mess="<?php echo esc_attr($mess);?>" data-before="<?php echo esc_attr($before_code);?>" data-code="<?php echo esc_attr(base64_encode($code));?>" class="coundownmobile" onclick="startcountdown(this); this.onclick=null;">
        <?php echo $title;?>
    </span>
    <?php
    return ob_get_clean();
}
add_action('wp_footer', 'countdown_script');
function countdown_script(){
    ?>
    <style>
        .coundownmobile{
            background: #e81e1e;
            border-radius: 10px;
            border: none;
            color: #ffffff;
            display: inline-block;
            text-align: center;
            padding: 10px;
            outline: none;
            cursor: pointer;
        }
        .coundownmobile.countdown-loading {
            background: #FF5722;
        }
        .coundownmobile.countdown-done {
            background: green;
        }
    </style>
    <script type="text/javascript">
        function startcountdown(btn){
            btn.classList.add("countdown-loading");
            let counter = btn.getAttribute('data-counter');
            let $code = btn.getAttribute('data-code');
            let mess = btn.getAttribute('data-mess');
            let before = btn.getAttribute('data-before');
            let startcountdown = setInterval(function(){
                counter--;
                btn.innerHTML = mess.replace(/%s/gi, counter);
                if(counter == 0){
                    if($code) {
                        btn.innerHTML = before + ' ' + atob($code);
                        btn.classList.add("countdown-done");
                    }
                    clearInterval(startcountdown);
                    return false;
                }}, 1000);
        }
    </script>
    <?php
}

You can use the shortcode [pass_countdown] to display the countdown button.

The specific parameters are as follows:

  • time: This is the countdown time, in seconds. The default is 10 seconds.
  • code: This is the password or code you want to share.
  • before_code: This is the text displayed before the password.
  • title: This is the text displayed on the button before it’s clicked.
  • mess: This is the countdown message displayed after clicking the button. %s represents the remaining seconds.

Example:

If you want to display a countdown of 20 seconds before showing the password “1234”, the shortcode will be as follows:

[pass_countdown code="1234" time="20"]
480520387 657957633334779 6814038772835954285 n
Admin (Nghia Vo)

Hi, I’m Nghia Vo: a computer hardware graduate, passionate PC hardware blogger, and entrepreneur with extensive hands-on experience building and upgrading computers for gaming, productivity, and business operations.
As the founder of Vonebuy.com, a verified ecommerce store under Vietnam’s Ministry of Industry and Trade, I combine my technical knowledge with real-world business applications to help users make confident decisions.

I specialize in no-nonsense guides on RAM overclocking, motherboard compatibility, SSD upgrades, and honest product reviews sharing everything I’ve tested and implemented for my customers and readers.

You Might Also Like

Headless vs Traditional WooCommerce: Which Architecture Wins?

Can AI Agents Safely Access Your WordPress Site?

Is WordPress Dead or Still Powering the Web in 2026?

WordPress 6.9.2 Disaster: Why You Should Never Auto-Update Immediately

Headless WordPress Explained: Is It Right for Your Site?

TAGGED:codecountdown button
Share This Article
Facebook Twitter Email Print
By Admin (Nghia Vo)
Follow:
Hi, I’m Nghia Vo: a computer hardware graduate, passionate PC hardware blogger, and entrepreneur with extensive hands-on experience building and upgrading computers for gaming, productivity, and business operations. As the founder of Vonebuy.com, a verified ecommerce store under Vietnam's Ministry of Industry and Trade, I combine my technical knowledge with real-world business applications to help users make confident decisions. I specialize in no-nonsense guides on RAM overclocking, motherboard compatibility, SSD upgrades, and honest product reviews sharing everything I’ve tested and implemented for my customers and readers.
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Trending

HETZNER HOSTING
Solutions & Troubleshooting

Why Hetzner Might Not Be the Right Choice for Beginners

March 7, 2026
Create a Simple Incrementing Number Effect with HTML and JavaScript 2
Solutions & Troubleshooting

Create a Simple Incrementing Number Effect with HTML and JavaScript

September 17, 2024
Top Free WordPress Plugins for Bloggers in 2025
Themes & Plugins

Top Free WordPress Plugins for Bloggers in 2025

May 3, 2025
How to Install and Use Google Analytics 4
Installation & Setup

How to Install and Use Google Analytics 4 (GA4) in 2025: A Step-by-Step Guide

April 21, 2025
Want to Protect Your Website
Security

Want to Protect Your Website? Never Do These 6 Things!

May 23, 2025
How to Change WordPress Login URL Without Plugins
Solutions & Troubleshooting

How to Change WordPress Login URL Without Plugins (100% Success)

September 9, 2024
Previous Next

You Might Also Like

WordPress 7.0 Finally Fixes 20 Years of Painful Collaboration Problems
Solutions & Troubleshooting

WordPress 7.0 Finally Fixes 20 Years of Painful Collaboration Problems

Admin (Nghia Vo) Admin (Nghia Vo) March 9, 2026
wordpress speed 2026
Solutions & Troubleshooting

WordPress Speed in 2026: The Only Hosting Checklist You Need

Admin (Nghia Vo) Admin (Nghia Vo) March 7, 2026
What Happens When Web Hosting Companies Get Acquired
Solutions & Troubleshooting

What Happens When Web Hosting Companies Get Acquired

Admin (Nghia Vo) Admin (Nghia Vo) March 6, 2026
wordpress shortcode 1
Solutions & Troubleshooting

WordPress Shortcodes: Complete Guide to Dynamic Content

Admin (Nghia Vo) Admin (Nghia Vo) March 4, 2026
How to Make Google Understand and Value Your Content
Solutions & Troubleshooting

SEO in the Age of AI: How to Make Google Understand and Value Your Content

Admin (Nghia Vo) Admin (Nghia Vo) June 5, 2025
Cannot Fetch Sitemap in Google Search Console
Solutions & Troubleshooting

Cannot Fetch Sitemap in Google Search Console

Admin (Nghia Vo) Admin (Nghia Vo) May 27, 2025
Previous Next
newsletter featured

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

Follow US on Social Media

Facebook Youtube Steam Twitch Unity

Copyright © 2024 ohhmua. All rights reserved.

OhhMua

Information

  • About
  • Terms & Conditions
  • Privacy Policy
  • Editorial Standards
Welcome Back!

Sign in to your account

Lost your password?