PHPackages                             tahiryasin/yii-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. tahiryasin/yii-shortcode

ActiveLibrary

tahiryasin/yii-shortcode
========================

Yii component that enables you to create WordPress like shortcodes.

59PHP

Since Mar 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/tahiryasin/yii-shortcode)[ Packagist](https://packagist.org/packages/tahiryasin/yii-shortcode)[ RSS](/packages/tahiryasin-yii-shortcode/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

yii-shortcode
=============

[](#yii-shortcode)

Yii-shortcode is a component for the [Yii PHP framework](http://www.yiiframework.com) that provides ability to create [WordPress](http://codex.wordpress.org/Shortcode) like shortcodes.

Usage
-----

[](#usage)

### Setup

[](#setup)

Download the latest release from [Yii extensions](http://www.yiiframework.com/extension/yii-shortcode).

Unzip the component under ***protected/components*** and add the following to your application config:

```
return array(
  'components' => array(
    'shortcode' => array(
        'class' => 'application.components.ShortCode',
     ),
  ...
  ...
  ),
);
```

***protected/config/main.php***

### Registring Shortcodes

[](#registring-shortcodes)

You can register as many shortcodes as you want in base controller or in any custom controller:

```
public function beforeAction($action)
  {
      Yii::app()->shortcode->add_shortcode('gallery', array($this, 'gallery_callback'));
	  Yii::app()->shortcode->add_shortcode('caption', array($this, 'caption_callback'));
	  return $action;
  }
```

***protected/components/Controller.php***

```
function gallery_callback($atts)
  {
      return "Gallery #{$atts['id']}";
  }
function caption_callback($atts, $content)
  {
      return '' . $content . '';
  }
```

***protected/controllers/SiteController.php***

#### Rendering ShortCode

[](#rendering-shortcode)

```
$content = 'My Gallery: [gallery id="123"]';
echo Yii::app()->shortcode->parse($content);
```

**The output would be:**`My Gallery: Gallery #123`

```
$content= 'Hi, check out this caption: [caption]My Caption[/caption]';
echo Yii::app()->shortcode->parse($content);
```

**The output would be:**`Hi, check out this caption: My Caption`

***protected/views/site/index.php***

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/43dabc5a5d623c5f5e58448549897da921df672ed4fe9456f7d4827a999ccbb4?d=identicon)[tahiryasin](/maintainers/tahiryasin)

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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