未加星标

Why Use CMB2 Over ACF for Custom Fields in WordPress

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二03 | 时间 2019 | 作者 红领巾 ] 0人收藏点击收藏

If you develop WordPress sites regularly, you know that using a custom field manager plugin is a must. Achieving a complex behavior and handle mixed fields is possible in WP but by default, not the most advanced and easy-to-use system.


Why Use CMB2 Over ACF for Custom Fields in WordPress

When you start to search for a custom option/meta solution, you will fastly find the Advanced Custom Field plugin developed by Elliot Condon. The ACF is one of the most popular extensions in the WordPress ecosystem although it is a partly paid one and mostly useful for the devs.

You can almost do any metadata related task with ACF, there are a ton of 3rd party extensions for it, and the support/documentation is fantastic.

I’m using ACF for ages now, and I’m satisfied with it, but this doesn’t mean that there aren’t any good other solution. For me finding another extension for metadata handling came when I started to develop a freely available theme; for this, I couldn’t redistribute the plugin (ACF), and I didn’t want to expect the users to buy it. At the point, CMB2 came into the picture.

What Can The CMB2 Plugin Do

WebDevStudios develop the CMB2 , so the support and the quality are guaranteed.

Using CMB2, you can create anything in some way that you can create in ACF. Of course, these are two different pieces of software, so they are works differently.

Two main difference is that: CMB2 using the WordPress Core methods when it comes to store or retrieve data. So to get something you can use get_post_meta() function. In CMB2 you don’t get an admin UI to register your fields, you have to set them up in your code; this is not just a disadvantage but an advantage too.

For the field registration here is an example where you first create a section (box):

add_action( 'cmb2_admin_init', 'pine_alpha_register_theme_options_metabox' ); function pine_alpha_register_theme_options_metabox() { $prefix = '_pine_alpha_'; $cmb_post = new_cmb2_box( array( 'id' => $prefix . 'post_fields', 'title' => esc_html__( 'Theme Specific Settings', 'pine-alpha' ), 'object_types' => array( 'post' ) ) ); $cmb_post->add_field( array( 'name' => esc_html__( 'Show this in slider?', 'pine-alpha' ), 'desc' => esc_html__( 'If you check this field, this post will be shown in the slider section in the header if it is enabled.', 'pine-alpha' ), 'id' => $prefix . 'show_in_slider', 'type' => 'checkbox', 'column' => true ) ); }

For more information about the API check out the documentation !

In my opinion, the WebDevStudios’s extension is intuitive, works well in a lot of cases, and has proper documentation. If you worked custom meta before there won’t be any problem to switching. Sure your code and some UI element will look a little different, but after the first project, this is not a problem.

As in the case of ACF there a lot of 3rd party extension to help create any different solution.

If you develop a theme, you can easily integrate it into your theme files but the best method to use TGM Plugin Activation and set up as a requirement.

Is it Worth to Switch To CMB2?

I think you don’t have to switch. For me, it is not a problem to use them in parallel. For the open-source project I use CMB2, and for the client jobs, I use ACF.

In WordPress there is always another often better solution which worth our time. We can learn a lot from these experiences so if you feel so give it a try!

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

代码区博客精选文章
分页:12
转载请注明
本文标题:Why Use CMB2 Over ACF for Custom Fields in WordPress
本站链接:https://www.codesec.net/view/628285.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(103)