0

I'm developing a company Website using Wordpress 4. This website needs some special, customized pages - with forms and GET and POST and a lot of stuff, so a lot of PHP code.

Now, a CMS' main purpose is to separate content and code and design and provide easy extension capabilities. How can I separate the logic of the custom templates from the raw text that these templates give out?

Example: Somewhere the template code needs to give out the text "Dear customer, please select the colour your wish to use:". Sadly, I as the web developer did some typos in this text. Now the content-authors (non-technicans) want to fix my typos. They would have to enter all the PHP code, which they never learned. Or they would have to ask me to fix it, but it's not really my job to fix typos. So, I actually need a logic to be able to do this: echo $colour_select_text, with $colour_select_text being easily changable in the regular Wordpress backend (just like editing regular Wordpress pages/posts).

What is a good way in Wordpress to separate custom PHP logic and custom content, so that non-coding authors can edit the texts outside the code and the actual coders can adjust the logic without breaking the actual content of the custom templates? Do I need to write a custom plugin for this as well (i.e. creating a MySQL table holding the texts, providing a backend form for changing them and write an PHP API to access them), or does Wordpress provide some kind of mechanism for this kind of tasks already?

  • 1
    You made the typos, but it's not your job to fix it? What a job! – SkyShab Nov 21 '14 at 0:48
  • @Aargh-a-Knot Was a bad example, I admit. I'm not a content author, but a coder. So it is not my job to change texts. Let's say it is not a typo but a product description that should change. – Foo Bar Nov 21 '14 at 13:38
  • Sorry, just having some fun at your expense. It sounds like you need to check out ACF (Advanced Custom Fields), and create an options page or in-post metaboxes to allow editing of the content in question. Or employ something similar within your own code. There's quite a bit of documentation about custom metaboxes and options pages out there. – SkyShab Nov 21 '14 at 15:36
  • 1
    I'm usually against locking yourself in with a vendor by using something like ACF, take a look at writing a plugin and register the meta boxes, options/settings pages, etc that you need for text and other things that need to be managed by non-technical staff. Pretty much every WordPress site I've done that's more than a trivial install and theme/plugin setup has a one-off, site specific plugin with general utility code. Edit: That also prevents you from polluting the functions.php of the active theme and allows for theme switching later. – Andrew Bartel Nov 21 '14 at 18:53
  • Wordpress provides custom meta functionality out of the box if you are just adding a few meta values to a page or post. Not the best user experience, but easy. I personally use a forked version of wpalchemy – SkyShab Nov 21 '14 at 23:22

Your Answer

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

Browse other questions tagged or ask your own question.