How to Limit Audio Plays in WordPress

If you add audio files to your WordPress site, limit how often users can play them. This is useful if you share exclusive audio content, music previews, podcasts, or voice recordings.

In this guide, you will learn different ways to limit audio plays in WordPress.

Method 1: Use a WordPress Audio Plugin

The easiest way to limit audio playback is to use a WordPress plugin. Several plugins allow you to restrict playback, set limits, or even disable downloads.

Useful Plugins

Here are some of the best plugins for controlling audio plays in WordPress:

AudioIgniter – Allows audio restrictions and track settings.
Compact WP Audio Player – Offers autoplay restrictions and audio limits.
Restrict Content Pro – Limits access to audio based on membership levels.
WP Membership Plugins – Restrict audio access for logged-in users.

How to Limit Audio Plays with AudioIgniter

  • Install the Plugin
  • Go to Plugins > Add New.
  • Search for AudioIgniter.
  • Click Install Now and Activate.
  • Create an Audio Playlist
  • Go to AudioIgniter > Add New Playlist.
  • Upload your audio files.
  • Enable Restrictions
  • Set playback limits (e.g., play X times per user).
  • Disable the download option.
  • Save and Embed the Audio Player
  • Copy the generated shortcode.
  • Paste it into a post or page.

Now, your audio files will have limited play per user!

Method 2: Use a Membership Plugin

A membership plugin is a great option to restrict audio access based on user roles.

Best Membership Plugins for Audio Control
MemberPress – Lock audio behind memberships.
Restrict Content Pro – Limit plays per user.
Paid Memberships Pro – Allow access only to paying users.

How to Limit Audio Plays with Restrict Content Pro

Install Restrict Content Pro
Go to Plugins > Add New.
Search for Restrict Content Pro.
Click Install Now and Activate.
Create a Membership Plan
Go to Restrict > Membership Levels.
Set access rules for audio files.
Restrict Audio Content
Edit your audio post or page.
Select Restrict Content and choose the membership level.

Now, only authorized users can play your audio files!

Method 3: Limit Plays Using Custom Code

You can use custom JavaScript and PHP to limit audio playback if you prefer a manual solution.

How It Works

This method tracks how often a user has played the audio and stops playback after a specific limit.

Steps to Add a Play Limit with JavaScript
Open Your WordPress Theme Editor
Go to Appearance > Theme File Editor.

Add this JavaScript to functions.php

<audio id=”myAudio” controls>

<source src=”your-audio-file.mp3″ type=”audio/mpeg”>

Your browser does not support the audio element.

</audio>

<script>

let playCount = 0;

let maxPlays = 3; // Set your play limit here

let audio = document.getElementById(“myAudio”);

audio.onplay = function() {

playCount++;

if (playCount >= maxPlays) {

audio.pause();

audio.controls = false; // Disable controls after limit

alert(“You’ve reached the maximum plays allowed.”);

}

};

</script>

Save and Test
Replace your-audio-file.mp3 with your actual audio file URL.
Try playing the audio – it will stop after 3 plays.

Method 4: Use Cookies to Track Audio Plays

You can use cookies to remember user play counts after they refresh the page.

Steps to Add a Cookie-Based Play Limit
Open Your WordPress Theme Editor.

Add This JavaScript Code to Your Theme:

<audio id=”myAudio” controls>

<source src=”your-audio-file.mp3″ type=”audio/mpeg”>

Your browser does not support the audio element.

</audio>

<script>

let audio = document.getElementById(“myAudio”);

let maxPlays = 3;

function getCookie(name) {

let match = document.cookie.match(new RegExp(‘(^| )’ + name + ‘=([^;]+)’));

return match ? parseInt(match[2]) : 0;

}

function setCookie(name, value, days) {

let date = new Date();

date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

document.cookie = name + “=” + value + “; expires=” + date.toUTCString() + “; path=/”;

}

let playCount = getCookie(“audioPlays”);

audio.onplay = function() {

playCount++;

setCookie(“audioPlays”, playCount, 1); // Store for 1 day

if (playCount >= maxPlays) {

audio.pause();

audio.controls = false;

alert(“You have reached the play limit.”);

}

};

</script>

Save and Test

After 3 plays, the audio will be disabled and won’t reset even if the page is refreshed.

Method 5: Hide the Audio Player After a Certain Number of Plays

If you want to remove the player entirely after reaching the play limit, modify the JavaScript like this:

audio.onplay = function() {

playCount++;

setCookie(“audioPlays”, playCount, 1);

if (playCount >= maxPlays) {

document.getElementById(“myAudio”).style.display = “none”;

alert(“Play limit reached. The audio is no longer available.”);

}

};

Now, after the limit is reached, the audio player disappears!