Skip to content
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

Open
joshcummingsdesign opened this issue Mar 4, 2017 · 5 comments
Open

Add docs for shortcode #7

joshcummingsdesign opened this issue Mar 4, 2017 · 5 comments

Comments

@joshcummingsdesign
Copy link
Owner

joshcummingsdesign commented Mar 4, 2017

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.

@joshcummingsdesign joshcummingsdesign changed the title Add option for shortcode Add docs for shortcode Mar 6, 2017
@FrankV01
Copy link

FrankV01 commented Mar 4, 2018

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.

@faizanumer
Copy link

faizanumer commented Jan 12, 2022

Hi there Josh,
I'm new to wp plugin development found your starter kit extremely helpful.
Everything works smoothly I'm just struggling with one thing where do I add my "add_shortcode()" code it doesn't seem to work in the main plugin file
Thanks!

@joshcummingsdesign
Copy link
Owner Author

@FrankV01 @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!

@faizanumer
Copy link

faizanumer commented Jan 12, 2022 via email

@joshcummingsdesign
Copy link
Owner Author

joshcummingsdesign commented Jan 12, 2022

Any time 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants