I have a class that will register some metaboxes in my custom theme and i need to fix some small problems with it. I have added a tinymce instance inside some metaboxes. I want to add also a text input field placed to the top of the metabox before the tinymce, this because I want to have the ability to add a title to the editor content that will be inserted. Is this possible using a single save callabck for both fields? Another question is about shortcodes, I've noticed that they will be saved with the content,but I want to strip them out. The only info I want to save are the images gallery ids that will be selected from the user, to put the images inside a swiper. Is this possible ? Here is an example of the code:

// the code is part of a class, I will omit some parts to go right to the point of the question
// here I'm creating the metabox. Is possible to avoid to repeat the code and register multiple metaboxes dynamically? 
// this metabox will create a column for my pages and posts
      __('Colonna 1'),
      array($this, 'theme_first_col_callback' ),
      array('page', 'post'),

// here are the callback
// the first one is for the editor, here I want to add the title text input
  public function theme_first_col_callback( $post )
    wp_nonce_field( basename( __FILE__ ), 'theme_col1_nonce' );
    $field_value = get_post_meta( $post->ID, '_col_1', false );
    @wp_editor( $field_value[0], '_col_1' );
// here i save the content, maybe strip shortcodes will work?
  public function theme_first_col_save( $post_id ) {
      // Checks save status
      $is_autosave = wp_is_post_autosave( $post_id );
      $is_revision = wp_is_post_revision( $post_id );
      $is_valid_nonce = ( isset( $_POST[ 'theme_col1_nonce' ] ) && wp_verify_nonce( $_POST[ 'theme_col1_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
      // Exits script depending on save status
      if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
      // Checks for input and sanitizes/saves if needed
      if( isset( $_POST['_col_1'] ) ) {
          update_post_meta( $post_id, '_col_1', $_POST[ '_col_1' ] );


Since sometimes I need multiple columns (now I registered only two metabox with tinymce) and I'm using vue on frontend to render the data, I need a way to preserve the metabox image gallery but stripping out the shortcode. Also I need a way to add new column in a dynamic way by click on a button on the post/page edit screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.