[Resolved] Is it possible to extend the Layout Metabox?

Home Forums Support [Resolved] Is it possible to extend the Layout Metabox?

Home Forums Support Is it possible to extend the Layout Metabox?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #552067
    Alvaro

    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

    GeneratePress 2.0.2
    GP Premium 1.6.2
    #552244
    Tom
    Lead Developer
    Lead Developer

    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!

    #558485
    Alvaro

    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

    #558629
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.