最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

metabox - Using Customizer API vs Custom Meta Box for custom content

programmeradmin3浏览0评论

I just started diving into the wordpress world and i'm trying to add custom content to a website, i looked at the Customizer API and Meta box and they seem to be both able to add what i want which is custom content but i don't know which one of them is suitable for that. I'm trying to add list of services to a services page that i've created.

I just started diving into the wordpress world and i'm trying to add custom content to a website, i looked at the Customizer API and Meta box and they seem to be both able to add what i want which is custom content but i don't know which one of them is suitable for that. I'm trying to add list of services to a services page that i've created.

Share Improve this question asked Mar 4, 2020 at 20:30 Black IsoBlack Iso 31 bronze badge 2
  • If you want to just add a list why not use the List Block? gogutenberg/blocks/list – RiddleMeThis Commented Mar 4, 2020 at 20:46
  • @RiddleMeThis im not trying to add a list as in a normal list there custom blocks thats show each services with a title and description and icon – Black Iso Commented Mar 4, 2020 at 20:54
Add a comment  | 

2 Answers 2

Reset to default 0

Neither!

Neither of these really make sense

Why Not A Metabox/Post Meta?

What you're describing is not an attribute of a page, so it doesn't make sense as post meta shown in a metabox.

Additionally:

  • You can't link directly to post meta
  • Adding post meta to site search is difficult, and makes search 100x slower
  • And if you did manage that, users wouldn't see the service they wanted, they'd just see the generic services page
  • You'd have to write all the code to store and save it, then write it all over again to display it. Plugins can make it easier but it's still a pain in the arse
  • Only your theme would be able to display the data
  • Metaboxes are kind of legacy meh with the new block editor. It's all about custom blocks and sidebar panels now

Why Not A Control In The Customizer?

It also isn't a site wide control to customize how your site behaves and looks, so it doesn't go in the customizer! Besides:

  • Those get stored as options and theme mods, so it doesn't scale as the list of services gets longer
  • The newer iterations of the block editor are introducing the full site editing interface that replaces the customizer
  • It's not easy to develop for

What you're describing is content.

So, you have 2 options that depend on just how in depth your services are.

Page Content

If you're literally just listing them all on a page, why not just have a services page that lists them? You could use column blocks to do the classic image on the left, text on the right thing, cover blocks if you wanted a whole section, or even build your own block!

But, if you want to be able to link to a specific service, or have an entire page for a service, the next option would be better suited

A Service Custom Post Type

Use register_post_type to register a service post type. You'll get lots of free stuff ( they can be turned off when calling register_post_type too:

  • You'll get an archive to list services at /services ( configurable )
  • Free templates ( single-service.php and archive-service.php anybody? )
  • An entire new section of WP Admin in the sidebar dedicated to Services
  • Free REST API endpoints ( set show_in_rest to true )
  • RSS feeds!
  • Dedicated URLs ( yoursite/services/gardening? )
  • Basic integration with SEO plugins
  • Post meta! Now you can have featured images and all sorts of information about the services stored. So much more flexibility
  • Child posts! What if your services had sub-services? Perhaps that gardening service has multiple specialities to hire

With a CPT, you could even register a custom taxonomy to organise them! Wouldn't it be nice to have a Service Type taxonomy? A County taxonomy for where the services are available? With their own URLs! yoursite/services/county/derbyshire?

On top of all that, if you put the registration code in a plugin, the services post type will work with every theme!

Like you mentioned, you could potentially use either one.

In your situation, I would probably lean towards using a meta box. The Customizer is separated from your pages and posts, meaning you would have to go into Appearance > Customize to edit your list. While with a Meta Box, you can have that display directly on your page's edit screen.

There are obviously more differences between the two but that would be the main one for me. You can read more about the Customizer here and Meta Boxes here.

发布评论

评论列表(0)

  1. 暂无评论