Reusable and site-wide content that can be used in a theme

Goal: To define content (phone number, address etc) in the admin area that can be used (called upon) in a theme.

Context: I am making a theme for a multi-site where every site will look the same, but have different content. The user should be able to easily add basic information in the admin area, preferably accessible through the left menu. The data fields will be predefined. It is important that each piece of data can be fetch independently.

My initial thoughts: Making a simple plugin where the user can enter the information. I was thinking of putting it in the functions.php file, but was not sure what would happen to the data if I made a new theme in the future.

Are there other obvious ways of accomplishing this that I haven't thought of? Any suggestions to how I could solve this in a future proof way?

Also, recommendations for good resources on the topic is appreciated!

Topic custom-content theme-development Wordpress

Category Web


I had a similar idea about 7 years ago and wrote a Django-inspired plugin called Chunks. It likely doesn't work anymore, but you can grab some ideas if you like:

https://wordpress.org/plugins/chunks/


Using functions.php inside your theme will have the functionality only for that theme.

I think a simple approach will be to create a plugin or a mu-plugin as @Benoti is suggesting where you will create a settings page that will be saved on options table.

There are a few guides to create admin pages: https://codex.wordpress.org/Creating_Options_Pages

There are also some ready made plugins like this ones: https://wordpress.org/plugins/search.php?q=options+page

From all available options I think is best to create your own options page as it is not very complicated and make it as a mu-plugin so all sites in your network will have it without the need of activation.


in your case I will make a plugin or a mu-plugin ( must-use plugin, which can not be desactivate) with a custom post type.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.