Wednesday, 22 October 2014

Moving Meta Boxes In The WordPress Editor

WordPress 3.8 introduced a new way to display messages in the old design of filters using a single column. A filter is a function that processes the data at certain points in the page life cycle. As the name suggests, a filter can be used to filter and / or manipulate certain data before displaying it in the browser or save the data to the database. Using a combination of filters and hooks action is not only possible to set the number of columns, but also to organize the order of the goal boxes within a column. In today's article, we will be building on what we have learned in the article Introduction to WordPress Meta Boxes much force a single column layout and the position of the goal boxes within the column.
One Column Layout

Meta boxes arrange a column one design requires the use of two filters. They are screen_layout_columns and get_user_option_screen_layout_ <post_type>. The first sets the number of columns in the design for each type of message, for $ columns [message] = 2; establishes a 2-column layout post and $ columns [message] = 1; 1. fit in "get_user_option_screen_layout_ <post_type>" does the same but in a different way. The message type specified in the filter name for the function to simply return the number of columns.

my_screen_layout_columns function ($ column) {
      $ Columns [<post_type>] = 1;
      return $ columns;
}

my_screen_layout function () {
      return 1;
}

add_filter ('screen_layout_columns', 'my_screen_layout_columns');
add_filter ('get_user_option_screen_layout_ <post_type>', 'my_screen_layout');

Implement the above, here is the code to define the layout for a custom message type called "menu". Note that in the my_screen_layout_columns () function, you must set the $ columns array element before returning:

my_screen_layout_columns function ($ column) {
      $ Columns ['menu'] = 1;
      return $ columns;
}

my_screen_layout_menu function () {
      return 1;
}

add_filter ('screen_layout_columns', 'my_screen_layout_columns');
add_filter ('get_user_option_screen_layout_menu', 'my_screen_layout_menu');

Change Order Meta Box

Once you have all Meta Boxes in a column, it is possible that your order is not to your liking. The position of a meta box on the page can be changed by removing and then including the $ context and $ priority arguments to re-add. The two arguments may seem too much, but they really work well together to provide precise control over the meta-box positioning.

No comments:

Post a Comment