Open DK-Web opened 5 years ago
Hey, here's how I have my shortcodes setup, I can confirm it works as expected.
In public/class-{plugin-name}-public.php
public function my_shortcode( $atts ) {
return 'Hello World';
}
In includes/class-{plugin-name}-loader.php
protected $shortcodes;
public function __construct() {
$this->actions = array();
$this->filters = array();
$this->shortcodes = array();
}
public function add_shortcode( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->shortcodes = $this->add( $this->shortcodes, $hook, $component, $callback, $priority, $accepted_args );
}
public function run() {
foreach ( $this->shortcodes as $hook ) {
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ) );
}
}
In includes/class-{plugin-name}.php
private function define_public_hooks() {
$plugin_public = new Book_With_Me_Public( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
$this->loader->add_shortcode( 'my_shortcode_tag', $plugin_public, 'my_shortcode' );
}
Hope this helps.
@indygill thank you. really helpfull if you start with this boilerplate or plugin development at all. should be part of the default boilerplate in my opinion or at least noted somewhere in which files you should look to extend the sample provided.
@indygill @DK-Web @adnoh Its seems like shortcode is not working[rendering] at backend or define_admin_hooks ... Is there something missing
This not works
Hey, here's how I have my shortcodes setup, I can confirm it works as expected.
In public/class-{plugin-name}-public.php
public function my_shortcode( $atts ) { return 'Hello World'; }
In includes/class-{plugin-name}-loader.php
protected $shortcodes; public function __construct() { $this->actions = array(); $this->filters = array(); $this->shortcodes = array(); } public function add_shortcode( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->shortcodes = $this->add( $this->shortcodes, $hook, $component, $callback, $priority, $accepted_args ); } public function run() { foreach ( $this->shortcodes as $hook ) { add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ) ); } }
In includes/class-{plugin-name}.php
private function define_public_hooks() { $plugin_public = new Book_With_Me_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_shortcode( 'my_shortcode_tag', $plugin_public, 'my_shortcode' ); }
Hope this helps.
Hey, here's how I have my shortcodes setup, I can confirm it works as expected.
In public/class-{plugin-name}-public.php
public function my_shortcode( $atts ) { return 'Hello World'; }
In includes/class-{plugin-name}-loader.php
protected $shortcodes; public function __construct() { $this->actions = array(); $this->filters = array(); $this->shortcodes = array(); } public function add_shortcode( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->shortcodes = $this->add( $this->shortcodes, $hook, $component, $callback, $priority, $accepted_args ); } public function run() { foreach ( $this->shortcodes as $hook ) { add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ) ); } }
In includes/class-{plugin-name}.php
private function define_public_hooks() { $plugin_public = new Book_With_Me_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_shortcode( 'my_shortcode_tag', $plugin_public, 'my_shortcode' ); }
Hope this helps.
Thank you. This helps a lot :)
Hey, here's how I have my shortcodes setup, I can confirm it works as expected.
In public/class-{plugin-name}-public.php
public function my_shortcode( $atts ) { return 'Hello World'; }
In includes/class-{plugin-name}-loader.php
protected $shortcodes; public function __construct() { $this->actions = array(); $this->filters = array(); $this->shortcodes = array(); } public function add_shortcode( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->shortcodes = $this->add( $this->shortcodes, $hook, $component, $callback, $priority, $accepted_args ); } public function run() { foreach ( $this->shortcodes as $hook ) { add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ) ); } }
In includes/class-{plugin-name}.php
private function define_public_hooks() { $plugin_public = new Book_With_Me_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_shortcode( 'my_shortcode_tag', $plugin_public, 'my_shortcode' ); }
Hope this helps.
Thank you, that did the trick!
Hey, here's how I have my shortcodes setup, I can confirm it works as expected.
In public/class-{plugin-name}-public.php
public function my_shortcode( $atts ) { return 'Hello World'; }
In includes/class-{plugin-name}-loader.php
protected $shortcodes; public function __construct() { $this->actions = array(); $this->filters = array(); $this->shortcodes = array(); } public function add_shortcode( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { $this->shortcodes = $this->add( $this->shortcodes, $hook, $component, $callback, $priority, $accepted_args ); } public function run() { foreach ( $this->shortcodes as $hook ) { add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ) ); } }
In includes/class-{plugin-name}.php
private function define_public_hooks() { $plugin_public = new Book_With_Me_Public( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_shortcode( 'my_shortcode_tag', $plugin_public, 'my_shortcode' ); }
Hope this helps.
Thank you so much man worked like a charm with out got any error.
Thank you! Works like a charm.
Hi, I can not get the shortcodes to work. Have now tried all the comments and approaches, as well as tutorials and commits and changed everything several times, but it just will not work. Only the shortcode is displayed in the frontend.
Loader:
Public:
Main Class:
Does anyone find the mistake? Many thanks for your help!