• Resolved patrick_here

    (@patrick_here)


    Hello,
    This is an outstanding plugin; thanks to everyone involved in its creation and maintenance.
    QUESTION: Currently my call to new_cmb2_box() is located in functions.php. Suppose I have a site with ten different Page Templates …each of them needing a unique set of 3 or more CMB2 metaboxes, each with its unique ‘name’ and ‘description’. If the code for all this were to be located in functions.php, the calls for creation of the metaboxes for each template would require perhaps 50 lines of php code (or more depending on the number of metaboxes) per Page Template …so the sum total could get very large.

    Is there a way to include the calls to new_cmb2_box() in Page-template-specific files so that that the code isn’t even executed if a visitor doesn’t visit a Page using a specific Template? I’m thinking, of course, of the potential impact on site speed as lines of CMB2 code are added in such an unusual situation.

    Thanks!
    Patrick

Viewing 1 replies (of 1 total)
  • Plugin Author Justin Sternberg

    (@jtsternberg)

    The lines of code will not have a significant performance impact to your site. Any attempts at conditionally loading boxes is going to cause problems with the save routine. Also important to note, as long as you’re hooking in to the cmb2_admin_init hook (docs), it will not load any of the CMB2 code during the frontend execution of your site (however, if you need the REST API capabilities for any of the boxes, then you will need to use the cmb2_init instead).

    Also in case you hadn’t found it, there is docs for limiting a box per page-template: https://github.com/CMB2/CMB2/wiki/Display-Options#limit-to-specific-page-templates

Viewing 1 replies (of 1 total)
  • The topic ‘Is Template-specific metabox creation possible?’ is closed to new replies.