Archived topic
Is it possible to extend the Layout Metabox?
3 replies · Started by Alvaro on April 16, 2018
Hi,
I'm thinking of adding a few options to control my frontpage display, I was thinking if it's possible to extend the Layout Metabox with extra tabs, to include my options panel.
Thanks.
Álvaro
We made the tabs filterable in GP 2.1, which is available for testing here: https://github.com/tomusborne/generatepress/issues/63
You can add a tab like this:
add_filter( 'generate_metabox_tabs', 'tu_add_metabox_tabs' );
function tu_add_metabox_tabs( $tabs ) {
$tabs['my_tab'] = array(
'title' => esc_html__( 'My Tab', 'generatepress' ),
'target' => '#my-target-div',
'class' => '',
);
}
Then you'd have to add your options div:
add_action( 'generate_layout_meta_box_content', 'tu_add_metabox_div' );
function tu_add_metabox_div( $stored_meta ) {
// $stored_meta is the meta values for the current post.
?>
<div id="my-target-div" style="display: none;">
Your options in here
</div>
<?php
}
Then you can hook into save_post to save your values, or use this:
add_action( 'generate_layout_meta_box_save', 'tu_save_custom_metabox' );
function tu_save_custom_metabox( $post_id ) {
// Save your custom meta
}
Hope this helps!
Hi Tom,
Thanks for your help and sorry for not getting to you earlier.
I'll have to test it thoroughly, I'm having issues regarding other parts of the project and had to stall the implementation of this options. But I'll get back to this.
Best,
Álvaro
Sounds good! :)