How to add add_meta_box to specific Page Template?

If your custom page template filename is foobar.php, you can use get_post_meta(): global $post; if ( ‘foobar.php’ == get_post_meta( $post->ID, ‘_wp_page_template’, true ) ) { // The current page has the foobar template assigned // do something } Personally, I like calling this inside my add_meta_boxes_page callback, and wrapping it around the add_meta_box() call itself. … Read more

Add metabox to document tab in gutenberg

Here is the solution. Hope it will help you const { registerPlugin } = wp.plugins; const { PluginDocumentSettingPanel } = wp.editPost; const MyDocumentSettingTest = () => ( &ltPluginDocumentSettingPanel className=”my-document-setting-plugin” title=”My Panel”&gt &ltp>My Document Setting Panel&lt/p> &lt/PluginDocumentSettingPanel> ); registerPlugin( ‘document-setting-test’, { render: MyDocumentSettingTest } ); https://github.com/WordPress/gutenberg/blob/master/packages/edit-post/src/components/sidebar/plugin-document-setting-panel/index.js#L86

How can i add some static text above the editor?

The best way would be using JavaScript to inject the element. Here’s the gist of the markup for that page: <div id=”poststuff”> <div id=”post-body” class=”metabox-holder columns-2″> <div id=”post-body-content”> <div id=”titlediv”> … other stuff … </div> <div id=”postdivrich” class=”postarea”> … other stuff … </div> </div> </div> </div> The titlediv is the title. The postdivrich is the … Read more

Can you make a custom metabox field be required to save a new post?

You can use jQuery as it already loaded on posts. The idea is to stop the form submit action. I have two html elements in my meta: <select name=”cars” class=”required”> <option value=”-1″>Choose a car</option> <option value=”volvo”>volvo</option> <option value=”saab”>saab</option> <option value=”bmw”>bmw</option> </select> <input type=”text” class=”required” placeholder=”Type year”> The form has an id of “post”. So with … Read more

How do the ‘tag’ and ‘category’ (default) taxonomies do ‘save_post’ action?

It’s informative to check out the /wp-admin/post.php file, that contains the edit_post() function that calls wp_update_post(), which is a wp_insert_post() wrapper. Here’s a skeleton for saving the assigned category terms: /** * Saving assigned category terms (skeleton) */ add_action( ‘admin_action_editpost’, function() { add_filter( ‘wp_insert_post_data’, function( $data, $parr ) { add_action( ‘save_post_post’, function( $post_ID, $post ) … Read more

How do I position meta_box on post edit screen after the title?

You cannot use a real metabox to do that, hook into edit_form_after_title instead. Here is a simple example: add_action( ‘edit_form_after_title’, ‘wpse_87478_pseudo_metabox’ ); add_action( ‘save_post’, ‘wpse_87478_save_metabox’ ); function wpse_87478_pseudo_metabox() { global $post; $key = ‘_wpse_87478’; if ( empty ( $post ) || ‘post’ !== get_post_type( $GLOBALS[‘post’] ) ) return; if ( ! $content = get_post_meta( $post->ID, … Read more

One metabox for multiple post types

Define an array of post types, and register the metabox for each one separately: function add_custom_meta_box() { $post_types = array ( ‘post’, ‘page’, ‘event’ ); foreach( $post_types as $post_type ) { add_meta_box( ‘custom_meta_box’, // $id ‘Custom Meta Box’, // $title ‘show_custom_meta_box’, // $callback $post_type, ‘normal’, // $context ‘high’ // $priority ); } }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)