Skip to content

Instantly share code, notes, and snippets.

@janzikmund
Created August 19, 2018 22:14
Show Gist options
  • Save janzikmund/cfa88e1a619b576d750561b060df5793 to your computer and use it in GitHub Desktop.
Save janzikmund/cfa88e1a619b576d750561b060df5793 to your computer and use it in GitHub Desktop.
WordPress class for automatically registered shortcode functions
<?php
/**
* Custom shortcodes
*/
class LHShortcodes
{
/**
* Constructor
*/
public function __construct()
{
// register all methods as shortcodes
$skip = ['__construct'];
$methods = get_class_methods($this);
foreach($methods as $method) {
if(in_array($method, $skip)) continue;
add_shortcode(str_replace('_', '-', $method), [$this, $method]);
}
}
// actual year
public function actual_year($atts, $content = "") {
return date('Y');
}
/*
// image grid
public function tb_image_grid($atts, $content = "") {
$atts = shortcode_atts( array(
'bg' => false,
'align' => false,
), $atts, str_replace('_', '-', __FUNCTION__) );
ob_start(); ?>
<div class="tb-row tb-align-<?php echo $atts['align']; ?>">
<img src="<?php echo $atts['bg']; ?>">
<div class="tb-content">
<?php echo apply_filters('the_content', $content); ?>
</div>
</div>
<?php return ob_get_clean();
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment