1

For example, in portfolio section I want to have 3 images that are positioned always in the same place in all the posts. I know there is a plugin that does this but I need to accomplish this without a plugin.

1 Answer 1

3

The best advice is to use the plugin. I can't think of any reason to rebuild functionality that already works well and exists. If you absolutely need this functionality in the theme, you can include the code from the plugin into your theme by removing the header in the plugin's main file and requiring it in your theme's functions.php file.

Please bear in mind that this is NOT considered as "best practice" and there are a couple of other steps that you will need to take to really make this work well:

  1. Change the name of all the functions. Adding a prefix like "myplugin_" to all functions should work well. Also, you will want to use this custom prefix on all global variables, class names, settings, localization slugs and anything else that WordPress might "see". This will avoid clashes in the event that the actual plugin is ever installed.

  2. load_plugin_textdomain() ahould be changed to load_theme_textdomain().

  3. plugins_url() will need to be changed to get_template_directory_uri().

  4. paths will need to be addressed.

At the end of the day, I would strongly urge you to allow your theme to support the plugin and degrade gracefully if the plugin is not installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.