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.
function wpse82477_add_meta_boxes_page() {
global $post;
if ( 'foobar.php' == get_post_meta( $post->ID, '_wp_page_template', true ) ) {
add_meta_box( $args );
}
}
add_action( 'add_meta_boxes_page', 'wpse82477_add_meta_boxes_page' );
You’ll just need to instruct users to save the page after assigning the template, so that the meta box appears.
Related Posts:
- How to enable custom fields for pages (if not a bad practice)?
- Custom field/meta populated by dropdown of existing posts?
- What is the index [0] for on post meta fields?
- Individual Widgets per Page
- Gutenberg add a custom metabox to default blocks
- ‘Preview Changes’ for custom meta boxes?
- Using TinyMce with textareas in meta boxes on custom post types
- add meta box – custom field : which to choose?
- Add metabox to document tab in gutenberg
- Custom field metabox not showing in back-end
- Having different sidebar content for MANY pages?
- How to hide meta box values from custom fields list?
- Adding another state (spam, reject, approve) to wordpress comments?
- Arrange custom fields with drag and drop?
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- Unable to get Preview of Uploaded image within a Custom Meta box
- Using media-upload.php to upload mp3 via custom fields
- extend Meta Box / Document Panel
- Add custom option to Standard Page Attributes Meta Box
- How to store the value of a custom field dropdown select for post referencing?
- Add multiple images to a page sidebar
- Only show metabox when date-value in other metabox is over?
- Custom Meta Boxes: Store two values in one repeatable field
- Populating meta box with select-list of existing posts, and assigning it to custom post types
- Create meta boxes that don’t show in custom fields
- How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
- Custom Page Template [closed]
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Metabox nonce PHP notice
- TinyMCE in Custom Metabox not loaded after upgrading from WP 3.1.4 to WP 3.2
- wp_editor in add_meta_boxes does not show gallery
- Calling Specific Pages with wp query Part II
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- Problem in custom meta boxes
- Loop through two different sets of custom fields
- Multiplile values checkbox or select in custom meta box
- Create custom field key upon theme activation
- Problem with adding exta field in metabox in custom post type
- Add input field to ‘Pages > Edit Page’ through functions.php
- Adding a custom field or metabox to the post-thumbnail widget?
- Custom fields to save multiple values
- How do I add custom_meta_box_id’s value?
- Undefined index error when saving content on metabox
- How to save multiple metaboxes?
- Metabox with multiple fields added by user and upload box
- Allow HTML in Custom Metabox area
- Metabox/Custom fields are not saving input data
- add meta box considers the selected option as post parent
- Custom field metabox not showing in back-end
- Issue on Creating Checkbox Field On Custom Post type
- WordPress admin area: select box with 12.000+ options
- How do I display a custom field in an existing form on the front end?
- How to display selected option from dropdown list in a metabox
- Save, update, get and sanitize post meta as HTML not plain
- Why does this javascript search function in the WordPress Admin not work?
- get wordpress post loop by meta box date
- Create Meta boxes dynamically
- Load one page with parent and child pages
- Update custom table on metabox POST
- Sub Field of File Field
- Save input form on custom field
- Page template is missing fields or is invalid when I updating the template
- Metabox value for post loop?
- how to modify a field’s size in a metabox : ROWS height, and scroll control?
- If metabox fields has content display content
- Append custom field items to content from plugin
- Get meta value when the page is a blog archive
- Can’t save meta field value if the title not set
- Display Data From This Custom Media Upload Meta Box?
- Why is wp_list_pages altering $post->ID of the page?
- When post is updated, custom metadata in text area field is overwritten
- Call the latest posts from a custom field group to be displayed on front-page
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- Custom Field select list is truncated
- wp_postmeta are updated for only one page
- My meta boxes update wp_postmeta of posts but not of pages. What is wrong with the code?
- Meta Box Data added to header redirect
- How to use page metadata while using wp_list_pages()?
- Getting content from custom fields of different pages on a single page
- Can i categorise my meta box?
- Decouple page name from page title
- Custom metaboxes not saving after switching themes
- Custom Metaboxes, multiple post selection
- I want my post to republish again after adding a custom field
- added a meta box to post however when saving menu while debug on throws a warning
- When editing a post with a custom meta box the values aren’t displaying correctly
- Use Metabox to enter Post Title
- Include custom fields into the content of a regular page
- Get fields from metabox array
- Creating an If/Else statement using WPAlchemy MetaBox radio boxs
- How to get the value of particular get $meta value in wordpress
- Display custom field value into content with hyperlink
- Using CMB2 Plugin to create text_date metabox (datepicker) How do I save multiple dates? [closed]
- How do delete a meta key?
- Dynamic background image used in css after selector
- How to add new Metadata options (Date, Author, etc.) for Posts?
- Saving multiple custom meta box fields
- Custom fields empty after refreshing page
- doesn’t save custom meta box data wordpress