How to Make a Page Refresh Button in WordPress on Click? [No Plugin]

Key Takeaways

  • JavaScript code adds a click event listener to a button with the class 'refreshpage' to refresh the page.
  • Elementor users can add the custom class 'refreshpage' in the Advanced tab of the button settings.
  • Gutenberg users can add the custom class 'refreshpage' in the Block tab of the button settings.
  • The location.reload() method used in the script may cause loss of unsaved data on the page.

Once, I wanted to add a Page Refresh Button to my client’s website to get updated details on a page second refresh.

However, most of the available plugins can be complicated to use and may slow down your website. That’s why I decided to share with you a simple solution that works with any button which has a class refresh page.

To make a page refresh button in WordPress, all you need to do is add a small piece of JavaScript code to your website.

This solution is simple, fast, and works with all page builders.

Table of Contents

Creating the Refresh Button in WordPress (Any Page Builder)

This can be done in any page builder, including Elementor and Gutenberg. Once you’ve added the button, you can style it using CSS to make it look however you want.

I will add the default Elementor Button widget to show you for demo purpose

Adding Button in Elementor for Page Refresh

Adding the JS Script on Page to Refresh Page on Click

As I was looking for a way to add a refresh button to my WordPress site without using a plugin, I made this simple JavaScript solution that works with any button with a class of “refreshpage”.

This script can be added to an HTML block in any page builder, including Elementor and Gutenberg, and will refresh the page when the button is clicked.

Here’s the code:

<script>

 jQuery(document).ready(function($) {
  // Find the button element by its class
  var refreshButton = $('.refreshpage');

  // Add a click event listener to the button
  refreshButton.on('click', function() {
    // Reload the page
    location.reload();
  });
});

</script>

This code adds an event listener to the button that listens for a click event. When the button is clicked, the location.reload() function is called, which refreshes the page.

Adding Script in Elementor HTML Block

With this simple JavaScript code, you can add a refresh button to any page in WordPress. Just by adding the Refresh page class, it will trigger the complete page reload.

Amazing, isn’t it?

If you were ever confused about understanding the difference between using a Child Theme or a Default Theme in WordPress, then check this blog, where I have gone in detail to help you understand what’s best for you.

Add Custom Class to the Button

To use this script, you’ll need to add a custom class to the button you want to use as the refresh button. In Elementor, you can add a custom class by clicking on the button, going to the Advanced tab, and adding “refreshpage” to the CSS Classes field.

Let’s add the custom CSS class in Elementor Button from the Advanced Tab

Adding Class to Elementor Button

In the case of Gutenberg, you can add a custom class by clicking on the button, going to the Block tab, and adding “refreshpage” to the Additional CSS Class(es) field.

Your Clients Deserve Faster Sites. You Deserve Less Headaches.

You got into this to build websites, not babysit them.

But here you are. Plugin conflicts at 2am. Clients pinging about downtime. Security patches you forgot about.

I run dedicated VPS hosting for agencies. Blazing fast. 24/7 monitored. Plugin updates on autopilot. Hacked site? I clean it same day.

You focus on clients. I keep the servers running.

Testing the Page Refresh on Click

Once you’ve added the custom class to your button, you can test the page from frontend and refresh by clicking on the button. If everything is set up correctly, the page should refresh when the button is clicked.

It’s worth noting that this script uses the location.reload() method to refresh the page, which can cause the page to lose any unsaved data. If you’re using this script on a page where users may be entering information, it’s a good idea to include a warning message or confirmation dialog to prevent accidental data loss.

I share what actually works in WordPress, SEO, and AI automation every week. Real numbers. Real experiments. No recycled advice.

Conclusion

In conclusion, creating a page refresh button in WordPress without using a plugin is a simple and effective solution for website owners who want to give their visitors the ability to refresh a page with just one click. By using a JavaScript function, we can easily add a class to any button and make it refresh the current page.

Frequently Asked Questions

What should I do if the refresh button isn't working?

If the refresh button isn't functioning, first ensure that you've added the JavaScript code correctly to your page. The code should include the jQuery function that listens for a click event on the button with the class 'refreshpage'. If the button is styled correctly and the class is applied, the page should refresh upon clicking. Additionally, check for any JavaScript errors in the browser's console that might be preventing the script from executing.

What is the best practice for adding a refresh button in WordPress?

The best practice for adding a refresh button is to ensure that the button has a clear purpose and is styled appropriately. Use the class 'refreshpage' to trigger the JavaScript function that refreshes the page. Additionally, consider adding a warning message for users who may lose unsaved data when the page reloads. This helps prevent accidental data loss and improves user experience.

How can I style the refresh button in Elementor?

To style the refresh button in Elementor, add the button widget to your page and navigate to the 'Style' tab. Here, you can customize the button's appearance, including colors, typography, and padding. Remember to add the custom class 'refreshpage' in the 'Advanced' tab to ensure the JavaScript functionality works correctly.

What happens if I forget to add the custom class to the button?

If you forget to add the custom class 'refreshpage' to the button, the JavaScript code will not recognize the button when clicked, and the page will not refresh. It's crucial to ensure that the class is correctly applied in the button settings, whether you're using Elementor or Gutenberg, to enable the refresh functionality.

Last reviewed: April 16, 2026

About the Author

Photo of Aditya Sharma CMO & Marketing Head
CMO · POSIMYTH Innovations · 7 years experience

CMO at POSIMYTH Innovations (500K+ users). I do marketing, SEO, server management, AI automation, content, and YouTube. Everything I write here comes from real work and real experiments.

WordPressElementorn8nAIClaudeAutomationServer
Stop Managing Servers!
Start Managing Clients.

Your clients deserve servers that never flinch.
You deserve to never think about servers again.

Whether you need a bulletproof setup built from scratch or someone to take over what you already have  I handle the infrastructure so your agency can focus on what it bills for.

No downtime calls. No 3am panics. No excuses.

Explore Further