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 and Gutenberg are compatible page builders for adding a refresh button in WordPress.
  • Adding a custom class 'refreshpage' is necessary for the button to trigger the page reload.
  • The location.reload() method used in the script can 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 page refresh button isn't working?

If the page refresh button isn't functioning, ensure that you have correctly added the custom class 'refreshpage' to your button. This class is essential for the JavaScript code to identify the button and trigger the refresh. Additionally, check that the JavaScript code is properly inserted in an HTML block within your page builder, as any errors in the script can prevent it from executing.

Can I use this refresh button method on any WordPress page builder?

This method for creating a page refresh button works with any page builder, including Elementor and Gutenberg. The flexibility of adding a custom class and JavaScript code allows you to implement this solution across different page designs without the need for plugins, making it a versatile option for WordPress users.

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

A best practice when using a page refresh button is to include a warning message or confirmation dialog, especially if users might be entering data on the page. Since the script uses location.reload(), it can lead to loss of unsaved information. Providing a prompt can help prevent accidental data loss and improve user experience.

Does using a page refresh button affect website performance?

Using a page refresh button itself does not inherently slow down your website, but it's important to consider the implications of frequent page reloads. If users refresh the page often, it can lead to increased server load and potentially affect performance, especially if the page contains heavy resources. Monitoring user behavior can help you assess if the button is being used excessively.

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

If you forget to add the custom class 'refreshpage' to your button, the JavaScript code will not be able to identify the button for the refresh action. This will result in the button appearing on the page but not functioning as intended. Always double-check that the class is correctly applied to ensure the script works properly.

Last reviewed: April 13, 2026

Aditya R Sharma

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.

Need Help With Your WordPress Site?

I help with managed hosting, SEO content, speed optimization, security, and automation. If something about your WordPress setup is slowing you down, let me know.

Explore Further