PHPackages                             wpsmith/shortcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wpsmith/shortcode

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wpsmith/shortcode
=================

WordPress shortcode.

1.0.0(7y ago)0831GPL-2.0+PHPPHP &gt;=5.6.0

Since Jun 26Pushed 6y ago1 watchersCompare

[ Source](https://github.com/wpsmith/Shortcode)[ Packagist](https://packagist.org/packages/wpsmith/shortcode)[ Docs](https://github.com/wpsmith/Shortcode)[ RSS](/packages/wpsmith-shortcode/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (13)Used By (1)

WordPress Shortcode Class
=========================

[](#wordpress-shortcode-class)

This library provides a skeleton to build shortcodes for WordPress.

Description
-----------

[](#description)

This library provides the skeleton for:

1. Registering the shortcode. If a shortcode exists with the same name, it will automatically remove the shortcode before adding this shortcode.
2. Ensuring that scripts/styles are only printed when the shortcode is being used.
3. Merging shortcode attributes with default attributes.

The `Shortcode` Base Class
--------------------------

[](#the-shortcode-base-class)

The shortcode is registered at `plugins_loaded` hook or immediately upon class instantiation via singleton implementation: `MyShortcode::get_instance()`.

This class checks the following to determine whether a shortcode exists on a page:

- The title
- The content
- The excerpt
- The Widget Title
- The Custom HTML Widget Content
- The Text Widget
- The Text Widget Content
- The Text Widget Content
- The Navigation Menu Link Attributes
- The Navigation Menu Title

Additionally, the class provides a filter `wps_shortcode_{}_is_active` to further extend checks to determine whether the shortcode exists on a page.

The `AjaxShortcode` Class
-------------------------

[](#the-ajaxshortcode-class)

This class extends the `Shortcode` base class providing additional features:

1. Skeleton for registering AJAX calls with checking the ajax refer nonce.
2. `doing_ajax()` static function.
3. `get_random_string()` static function.

Installation
------------

[](#installation)

To install via composer:

```
composer require wpsmith/shortcode

```

Otherwise copy the `Shortcode` (and `AjaxShortcode`) class(es) to your folder.

Usage
-----

[](#usage)

This library is easy to use in two simple steps:

1. Extend the class implementing the method `public function shortcode( $atts, $content = null ){}`. Note:
    - Your defaults as defined in `get_defaults()` method will already be merged (and also available via `$this->atts`)
    - Your script(s)/style(s) as enqueued in `enqueue_scripts()` method will already be printed or enqueued.
2. Instantiate the singleton in your theme/plugin: `MyShortcode::get_instance()`.

Optionally, you can do the following:

- Implement `register_scripts()` method to register your script differently from enqueing your script. This is highly recommended if you are using this within a distributed theme or plugin.
- Implement `init()` method to do some more initializing when the shortcode is instantiated.
- Implement `get_defaults()` to set some default parameters to be merged and thus always present.

Examples
--------

[](#examples)

You can find these and more examples at [Shortcodes](https://github.com/wpsmith/Shortcodes).

- [Basic Shortcode \[search\_form\] Example](https://github.com/wpsmith/Shortcodes/blob/master/src/SearchForm.php)
- [Basic Shortcode \[email\] Example with Defaults](https://github.com/wpsmith/Shortcodes/blob/master/src/Email.php)
- [Shortcode \[parallax\_image\] Example with a script/style](https://github.com/wpsmith/Shortcodes/blob/master/src/ParallaxImage.php)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~49 days

Total

12

Last Release

2688d ago

Major Versions

0.1.0 → 1.0.02019-02-21

PHP version history (2 changes)0.0.1PHP &gt;=5.2.4

0.1.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/46adebc3eebe7494dba592e75ac8f8572222050648b0283515b4a5896648d846?d=identicon)[wpsmith](/maintainers/wpsmith)

---

Top Contributors

[![wpsmith](https://avatars.githubusercontent.com/u/817366?v=4)](https://github.com/wpsmith "wpsmith (20 commits)")

---

Tags

wordpressshortcodesshortcode

### Embed Badge

![Health badge](/badges/wpsmith-shortcode/health.svg)

```
[![Health](https://phpackages.com/badges/wpsmith-shortcode/health.svg)](https://phpackages.com/packages/wpsmith-shortcode)
```

###  Alternatives

[webwizo/laravel-shortcodes

Wordpress like shortcodes for Laravel 11, 12 and 13

217700.9k8](/packages/webwizo-laravel-shortcodes)[maiorano84/shortcodes

Implement Shortcode syntax anywhere

7766.0k5](/packages/maiorano84-shortcodes)[pingpong/shortcode

Laravel - Simple shortcode based on wordpress shortcode

4040.5k1](/packages/pingpong-shortcode)[jtsternberg/shortcode-button

Tinymce and Quicktag buttons (and modals) for outputting shortcodes. Built to work with CMB2.

781.3k1](/packages/jtsternberg-shortcode-button)[brouwers/shortcodes

Wordpress like shortcodes for Laravel 4.2

2012.7k1](/packages/brouwers-shortcodes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
