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.
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.
Share Improve this question asked Mar 6, 2020 at 2:08 HeidiWFHeidiWF 32 bronze badges1 Answer
Reset to default 0Typically 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.