Lana Downloads Manager Shortcode

Below, you’ll find a detailed guide on how to add the Lana Downloads Manager 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 Lana Downloads Manager Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Lana Downloads Manager Plugin and the shortcodes it provides:

Plugin Icon
Lana Downloads Manager

"Lana Downloads Manager is a comprehensive plugin for WordPress that simplifies your file management. It makes the process of managing, tracking, and controlling file downloads on your website seamless."

★★★★★ (15) Active Installs: 3000+ Tested with: 6.0.6 PHP Version: false
Included Shortcodes:
  • [lana_download]

Lana Downloads Manager [lana_download] Shortcode

The Lana Downloads Manager shortcode is a powerful tool for managing file downloads. It enables the creation of a download button, with customizable text, for a specified file or post. The shortcode also includes an optional download counter, displaying the total number of downloads for the file. The shortcode is flexible, allowing either the file’s ID or path to be used for identification.

Shortcode: [lana_download]

Parameters

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

  • id – The unique identifier of the download file.
  • file – The specific path of the download file.
  • text – The custom text displayed on the download button.
  • counter – Controls display of download count on the button.

Examples and Usage

Basic example – The shortcode displays a download button for the specified download post ID. The button text will default to “Download”.

[lana_download id="123" /]

Advanced examples

Using the shortcode to display a download button for a specific file by referencing its path. The button text will default to “Download”.

[lana_download file="path/to/file" /]

Using the shortcode to display a download button with custom text. The button will show the number of downloads if the counter attribute is set to true.

[lana_download id="123" text="Click here to download" counter=true /]

Using the shortcode to display a download button for a specific file, with custom text and without a download count.

[lana_download file="path/to/file" text="Download this file" counter=false /]

Using the shortcode to display a download button with the post title as the button text.

[lana_download id="123" text="%post_title%" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'lana_download', 'lana_download_shortcode' );

Shortcode PHP function:

                    function lana_download_shortcode( $atts ) {
	$a = shortcode_atts( array(
		'id'      => '',
		'file'    => '',
		'text'    => __( 'Download', 'lana-downloads-manager' ),
		'counter' => true,
	), $atts );

	$lana_downloads_manager_counter = get_option( 'lana_downloads_manager_counter', true );

	if ( ! empty( $a['id'] ) ) {
		$lana_download = get_post( $a['id'] );
	}

	if ( ! empty( $a['file'] ) ) {
		$lana_download = get_page_by_path( $a['file'], OBJECT, 'lana_download' );
	}

	/** check lana download */
	if ( ! isset( $lana_download ) ) {
		return '';
	}

	/** check is post */
	if ( ! is_a( $lana_download, 'WP_Post' ) ) {
		return '';
	}

	/** post title to text */
	if ( '%post_title%' == $a['text'] ) {
		$a['text'] = $lana_download->post_title;
	}

	$output = '<div class="lana-download-shortcode">';

	/** download button */
	$output .= '<p>';
	$output .= '<a class="btn btn-primary lana-download" href="' . esc_attr( lana_downloads_manager_get_download_url( $lana_download->ID ) ) . '" role="button">';
	$output .= esc_html( $a['text'] ) . ' ';

	/** counter */
	if ( $a['counter'] && $lana_downloads_manager_counter ) {
		$output .= '<span class="badge">';
		$output .= lana_downloads_manager_get_download_count( $lana_download->ID );
		$output .= '</span>';
	}

	$output .= '</a>';
	$output .= '</p>';

	$output .= '</div>';

	return $output;
}
                    

Code file location:

lana-downloads-manager/lana-downloads-manager/lana-downloads-manager.php

Conclusion

Now that you’ve learned how to embed the Lana Downloads Manager 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 *