0

I am fairly new to Wordpress development so I apologize for my ignorance.

How can I alter the static information on my pages (IE not entries or page content) through the Theme Customizer API?

Is it possible to change static text on my pages so that I can allow my client to access the Theme Costumizer API and alter the text of paragraphs, buttons, h1's and such?

I know I can do this for things such as the page title and the page motto, also the page logo, but I wanna know if I can make more static info editable through this API. Or perhaps the better approach is to create metaboxes for specific pages and tell my client to type the text he wants on the metaboxes, but this does not have the visual dynamic appeal that the Theme Customizer API seems to have.

Hopefully I phrased my question properly, and thank you in advance.

0

You could put that kind of thing in the Customizer, but I wouldn't. It's probably too much content for there, which is really designed for site-wide settings, not content on individual pages.

Meta fields on the page using a plugin

A better approach is closer to what you were saying, storing meta information on individual pages. While meta boxes by default are not visually appealing, there are several meta plugins that do a good job of presenting editable fields in a friendly way. The one I use is Advanced Custom Fields (ACF). There's 3 parts:

1) Define your fields, groups, etc. in the Custom Fields admin menu.

You can create text fields, text areas, links, checkboxes, etc. Even better, you can create "repeater fields", i.e. allow the user to create several of a specific thing, groups, conditional logic, and more. Each field you create gets a slug by which you will reference it.

Each group you set up there you also assign to pages and posts conditionally.

2) On the posts you set up your group to appear, you input data into the fields by going to that post's editor page.

3) On the page template file (php), you reference those fields.

ACF provides a lot of great helper functions. The most simple is get_field('____'). So if you created a field called "Page Subtitle", it probably got the slug, "page_subtitle", and on your page template you might write,

if ( get_field( "page_subtitle" ) ){
    echo "<h2 class='page-subtitle'>" . get_field( "page_subtitle" ) . "</h2>";
}

Repeater fields are a little more complex, but the ACF site has a ton of great examples.

Developing for the future

Gutenberg was introduced in WordPress 5.0, and it replaces the content editor. If possible, it's worth seeing if you can embrace the Gutenberg mindset of letting users define the page layout using predefined blocks.

There is still a place for post meta, i.e. when you need a field for a part of a page that is not part of the main content area, but whenever you are able to use blocks instead you give your user more control over when and where layout elements appear.

There's even a new supercharged form of custom fields where you create custom fields for custom blocks!

More and more of WordPress in the near future will likely revolve around this type of approach, so this is a good time to jump in and embrace it.

  • ACF seems like it has everything I need as of right now, and I was just reading about Gutenberg, which seems like a great concept, thank you for your in depth answer! – Mauricioenvy Mar 1 at 16:16

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.