https://github.com/underpin-wp/shortcode-loader
Underpin loader for shortcodes
https://github.com/underpin-wp/shortcode-loader
shortcodes underpin wordpress
Last synced: about 2 months ago
JSON representation
Underpin loader for shortcodes
- Host: GitHub
- URL: https://github.com/underpin-wp/shortcode-loader
- Owner: Underpin-WP
- Created: 2021-05-03T22:01:09.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-24T21:42:04.000Z (over 4 years ago)
- Last Synced: 2025-03-08T01:01:52.415Z (over 1 year ago)
- Topics: shortcodes, underpin, wordpress
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Underpin Shortcode Loader
Loader That assists with registering shortcodes to a WordPress website.
## Installation
### Using Composer
`composer require underpin/shortcode-loader`
### Manually
This plugin uses a built-in autoloader, so as long as it is required _before_
Underpin, it should work as-expected.
`require_once(__DIR__ . '/underpin-shortcodes/shortcodes.php');`
## Setup
1. Install Underpin. See [Underpin Docs](https://www.github.com/underpin-wp/underpin)
1. Register new shortcodes menus as-needed.
## Example
A very basic example could look something like this.
```php
// Register shortcode
underpin()->shortcodes()->add( 'shortcode-key', [
'shortcode' => 'custom-shortcode', // Required. Shortcode name.
'defaults' => [ 'foo' => 'bar' ], // Default atts. See shortcode_atts
'shortcode_actions_callback' => function ( $parsed_atts ) { // Required. Shortcode action.
return $parsed_atts['key']; // 'value'
},
] );
// Shortcode output examples
do_shortcode( '[custom-shortcode foo="baz"]' ); // baz
do_shortcode( '[custom-shortcode]' ); // bar
```
Alternatively, you can extend `Shortcode` and reference the extended class directly, like so:
```php
underpin()->shortcodes()->add('shortcode-key','Namespace\To\Class');
```