Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Bootstraps WordPress Shortcodes functions
*
* @package Studiometa
*/

namespace Studiometa\Managers;

use Studiometa\Managers\ManagerInterface;
use Timber\Timber;

/** Class */
class ShortcodesManager implements ManagerInterface {
// phpcs:ignore Generic.Commenting.DocComment.MissingShort
/**
* @inheritDoc
*/
public function run() {
add_shortcode( 'studiometa_example', array( $this, 'add_example_shortcode' ) );
}


/**
* Add example shortcode
*
* @param array $params Shortcode parameters.
* @return template
*
* @example [studiometa_example foo="bar"]
*/
public function add_example_shortcode( $params ) {
// Takes the array keys, sets these as variable.
$attr = shortcode_atts(
array(
'foo' => __( 'Default foo param value', 'studiometa' ),
),
$params
);

return Timber::compile(
'shortcodes/example.twig',
array(
'foo' => $attr['foo'],
)
);
}
}
2 changes: 2 additions & 0 deletions template/web/wp-content/themes/<%= slug %>/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Studiometa\Managers\AssetsManager;
use Studiometa\Managers\CustomPostTypesManager;
use Studiometa\Managers\ManagerFactory;
use Studiometa\Managers\ShortcodesManager;
use Studiometa\Managers\TaxonomiesManager;
use Studiometa\Managers\ThemeManager;
use Studiometa\Managers\TwigManager;
Expand Down Expand Up @@ -64,6 +65,7 @@ function () {
new AssetsManager(),
new CustomPostTypesManager(),
new TaxonomiesManager(),
new ShortcodesManager(),
<%_ if (acf) { _%>
new ACFManager(),
<%_ } _%>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{#
/**
* @file
* Example shortcode
*
* Available variables:
* - foo
*/
#}
Shortcode value is {{ foo }}