0

I am building a native mobile app where I need to display categories of products in different screens, and my client uses Wordpress as their CMS. I see that in order to return images from a gallery, I will need to use get_post_galleries() or get_post_gallery() per the instructions here:

How to get the attached gallery in the rest API?

My question is, to which file do I add the custom endpoints? So far my CMS is very bare bones so for the purposes of this question, you can assume I only have the files included with a new Wordpress installation.

0

Typically changes like this you would either create a plugin or create a child theme and put your code in your child theme's functions.php file. You make changes to a child theme because if your theme updates you will lose any changes you have made directly to it.

Code in a plugin is always run as long as the plugin is active, where as code in a theme or child theme won't work if you change themes down the road. If the changes you want to make are not theme specific its probably best to just create a small plugin. Which is really nothing more than adding a comment at the top of a PHP file.

Here is an example plugin...

<?php
    /*
        Plugin Name: Example Plugin
    */

    // Your PHP here

Name this file, something like example-plugin.php, put it in the plugin directory then activate it in the admin.

Here is some info on creating a child theme.

Good article on plugins vs themes.

2
  • Thank you for the answer. I am not using any special theme as I only need WP for the rest api.
    – HeidiWF
    Mar 6 '20 at 2:28
  • Yeah I would suggest just creating a small plugin, I updated my answer to include more info on creating plugins. Mar 6 '20 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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