-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs for shortcode #7
Comments
Is this why my widget renders output in the bottom of my posts? It doesn't seem to happen on pages, just posts? This doc doesn't exist yet, even in draft form, does it? I don't mind enhancing documentation while I work but I can't cold-write them... I'm new to widgets in WordPress. |
Hi there Josh, |
@FrankV01 @faizanumer Right now I have the render method being called in In public function addShortcodes() {
add_shortcode('my_shortcode', function () {
echo 'Hello World';
});
} Then, use the loader class to hook it to the private function define_frontend_hooks() {
$plugin_frontend = new Frontend($this->plugin_slug, $this->version, $this->option_name);
$this->loader->add_action('wp_enqueue_scripts', $plugin_frontend, 'assets');
$this->loader->add_action('wp_footer', $plugin_frontend, 'render');
$this->loader->add_action('init', $plugin_frontend, 'addShortcodes'); // Add this line
} There might be better ways of doing this, but this should work for now 👍 Let me know if you have any other questions! |
Oh man it worked thank you so much for taking the time to reply to this
you’re a life saver Many Thanks 😊 Have a great day ahead
God Bless!
…On Thu, 13 Jan 2022 at 12:24 AM, Josh Cummings ***@***.***> wrote:
@FrankV01 <https://github.com/FrankV01> @faizanumer
<https://github.com/faizanumer> Right now I have the render method being
called in wp_footer. I've been working on a v3 of this project that will
clear up this issue, but here's what I'd suggest in the meantime.
In class-frontend.php create a new method called addShortcodes and put
your add_shortcode calls there.
public function addShortcodes() {
add_shortcode('my_shortcode', function () {
echo 'Hello World';
});
}
Then, use the loader class to hook it to the init action in the
define_frontend_hooks method of class-plugin.php like so:
private function define_frontend_hooks() {
$plugin_frontend = new Frontend($this->plugin_slug, $this->version, $this->option_name);
$this->loader->add_action('wp_enqueue_scripts', $plugin_frontend, 'assets');
$this->loader->add_action('wp_footer', $plugin_frontend, 'render');
$this->loader->add_action('init', $plugin_frontend, 'addShortcodes'); // Add this line
}
There might be better ways of doing this, but this should work for now 👍
Let me know if you have any other questions!
—
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AN5EF7YDU74SZJ77XD6IU5TUVXIO7ANCNFSM4DCM5J6Q>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Any time 😊 |
Some frontend code will be powered by shortcodes or will be called in different hooks. Right now the render method is being called in the 'wp_footer' hook. This needs to be clearly documented.
The text was updated successfully, but these errors were encountered: