Is there any tutorial how to put shortcodes and custom post types into plugin?
This is a quick how to
- Create a directory and name it anything you wish ( my-shortcodes-and-cpt-plugin )
- Create an index.php inside it and put this content in it:
<?php /* Plugin Name: Your Plugin Name Description: Your Descriptions Version: 1.0 Author: Myself */ include('shortcodes.php'); include('post-types.php'); ?>
- Then create both of the included files (shortcodes.php and post-types.php) and in shortcodes.php put your shortcodes codes, and in post-types.php enter your post types codes.
- Enqueue your CSS and JS files in your PHP files.
- Troubleshoot the probable issues.
Actually it’s not really different with what you are doing currently in your theme. You are just moving your codes into a plugin.
Just make sure that your theme will work even if your plugin is not activated.
Hope this helps you
Yes it’s really help me, now it works everything is fine, and one more thing, when i publish theme do i need to put my “shortcode” plugin into theme files or separate plugin from theme, and do i need to put shortcode css and js files into plugin folder.
I’m happy that it helped You should put the CSS and JS files in both plugin and theme and then enqueue them. Actually you should put some CSS files to make your plugin just works with other themes (So minimal) and then make your theme specific CSS codes in the theme itself.
And the best way to bundle your plugin into your theme, is to activate it with TGM plugin. This way your plugin will install almost automatically once a client install your theme and users will be able to upgrade to your latest version easily.
- Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
- Open a support ticket if you would like specific help with your account, deposits or purchases.
- Item Support by authors is optional and may vary. Please see the Support tab on each item page.
Most of all, enjoy your time here. Thank you for being a valued Envato community member.