Radio Player Shortcode

Below, you’ll find a detailed guide on how to add the Radio Player Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Radio Player Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Radio Player Plugin and the shortcodes it provides:

Plugin Icon
Radio Player – Live Shoutcast, Icecast and Any Audio Stream Player for WordPress

"Radio Player is a dynamic WordPress plugin, perfect for live audio streaming. It supports Shoutcast, Icecast and any other audio streams, transforming your site into a virtual radio station."

★★★★✩ (76) Active Installs: 5000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • []

Radio Player [radio_player] Shortcode

The Radio Player shortcode is a functional element that renders a radio player on your WordPress site. The shortcode is: [radio_player]. This shortcode uses the ‘render_player’ function, which checks for the player’s ID and type. If a valid player is found, it generates a div element with the player’s configuration data. It also ensures the necessary scripts are enqueued for the player to work correctly.

Shortcode: [radio_player]

Parameters

Here is a list of all possible null shortcode parameters and attributes:

  • id – Unique identifier of the radio player
  • player_type – Determines the type of the radio player

Examples and Usage

Basic example – The shortcode is used to render a radio player by referencing its unique ID.

[radio_player id=1 /]

Advanced examples:

Example 1 – The shortcode is used to render a radio player by referencing its unique ID and specifying the player type as ‘shortcode’.

[radio_player id=1 player_type='shortcode' /]

Example 2 – The shortcode is used to render a radio player by only specifying the player type as ‘shortcode’. In this case, the player ID is not provided, so the first available radio player will be rendered.

[radio_player player_type='shortcode' /]

Example 3 – The shortcode is used without any parameters. In this case, the first available radio player will be rendered with the default player type.

[radio_player /]

These examples demonstrate the flexibility of the shortcode in rendering the radio player. You can specify the player ID and type to customize the player according to your needs.

PHP Function Code

In case you have difficulties debugging what causing issues with [null] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'radio_player', array( $this, 'render_player' ) );

Shortcode PHP function:

function render_player( $atts )
    {
        $is_preview = isset( $_GET['preview'] );
        $atts = shortcode_atts( array(
            'id'          => '',
            'player_type' => 'shortcode',
        ), $atts );
        $id = intval( $atts['id'] );
        $player = radio_player_get_players( $id );
        if ( empty($player['status']) && !$is_preview ) {
            return;
        }
        $player_type = $atts['player_type'];
        $config = $player['config'];
        $config['id'] = $id;
        // Enqueue frontend scripts
        Radio_Player_Enqueue::instance()->frontend_scripts();
        return sprintf( '<div class="radio_player" data-player-type="%1$s"data-data="%2$s"></div>', $player_type, base64_encode( json_encode( $config ) ) );
    }

Code file location:

radio-player/radio-player/includes/class-shortcode.php

Conclusion

Now that you’ve learned how to embed the Radio Player Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

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