When we first started to submit the odd plugin to the WordPress plugin repository, we needed a means of providing an enhanced download link from our website. The answer came by way of a little download box with information sourced via the WordPress API. We wanted to include a title, basic description, download link, version details, and download count - and WP's API provides this. This article will provide you with the necessary WordPress shortcode that'll render an information download box in your WordPress page or post.
The result of our code is as follows:
The shortcode I used to generate this specific information was as follows: [bmplugin name="simple-audio-player"]
.
There's a large amount of data returned via the WP API. To avoid hogging realestate we've added the update time and tested version text to the Download
and Plugin Page
links as link titles.
WordPress Shortcode
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.
The image I've used can be downloaded from here . Alter it in your shortcode along with the background color and border style.
If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.
Shortcode Attributes
name
name
of your plugin is the only attribute that is required. While the plugin name is generally accepted, the plugin slug is preferred to avoid errors.title
title
is optional. By default, the plugin title as used in the WordPress repository will be used. To use your own use title="my title in here"
.description
description
is optional. By default, the plugin title as used in the WordPress repository will be used. To use your own use description="my description in here"
.author
author="0"
or alter your shortcode function.n
number_format()
function. If you choose not return the count in this manner, use n="0"
or alter the shortcode function.trim
trim="25"
. It's used so long descriptions don't run longer than is aesthetically pleasing.image
bgcolor
bgcolor
with bgcolor="#ffffff"
or code a permanent change into the shortcode function.border
border
with border="#000000"
or code a permanent change into the shortcode function.cache & cache_error
cache
time refers to the time the result is cached. The cache_error
time refers to the time you'll cache an error message before trying again.PHP Function
The following PHP function may be used outside of WordPress. The primary differences are detailed below. Usage requires Simple Cache With PHP.
The primary difference between this and the WP version is that we truncate the description text to a character length - not a word count. If our means of truncation doesn't agree with you, select an alternative function here.
Considerations
- You don't need to have anything to do with any of the plugins to be able to retrieve and display the data, making it an effective way of displaying information on review sites and blogs.
- For inactive plugins, consider using a longer cache period to avoid repeated requests to the WordPress API.
- A collection of the APIs used on the WordPress website are available here .
Download
Title: Display a WordPress Plugin Download Box
Description: Display a WordPress Plugin Download Box with Links and Download Count.
Download • Version 0.2, 12.2K, zip, Category: WordPress Plugins (General)
WordPress Shortcodes, (1.6K) PHP Code & Snippets, (1.7K)