You cannot do that with pure PHP, because the fields are fetched from existing fields, and there is no hook. But you can use JavaScript, check if the post type supports custom fields and the field does not exist already – and insert it:
<?php # -*- coding: utf-8 -*-
/* Plugin Name: Extend custom fields */
add_action( 'admin_footer-post-new.php', 'wpse_98269_script' );
add_action( 'admin_footer-post.php', 'wpse_98269_script' );
function wpse_98269_script()
{
if ( ! isset ( $GLOBALS['post'] ) )
return;
$post_type = get_post_type( $GLOBALS['post'] );
if ( ! post_type_supports( $post_type, 'custom-fields' ) )
return;
?>
<script>
if ( jQuery( "[value="demo_data"]" ).length < 1 ) // avoid duplication
jQuery( "#metakeyselect").append( "<option value="demo_data">demo_data</option>" );
</script>
<?php
}
Related Posts:
- How to display custom field in woocommerce orders in admin panel?
- Get a list of all available fields in the User Profile
- Enabling shortcodes for custom fields
- Add options to featured image
- Authors details such as social media links, emails etc → Is this Meta or something else?
- Assign category using custom field?
- Function to Download External Images to My Site
- Checked() showing up twice in custom fields
- How to use max and min values of custom fields
- Woocommerce Storefront WordPress Ignore Media Gallery Images and use External 3rd Party Host
- Customizer field value into functions.php variable
- Auto delete post if certain custom field data is empty
- How to display custom option field in woocommerce orders in admin panel?
- How to add a slide toggle to the Woocommerce-Layout__Activity-Panel area in the orders admin page
- What WordPress function to use to get meta value by using meta keys?
- Removing custom meta data
- Change label for registration Fields
- Custom Attachment Caption Fields
- Default Custom Field Value Automatically Update
- WordPress function saves a post twice and updates all posts
- ACF not showing
- How to retrieve the values of a sub-field in the first and last row of an (ACF) repeater inside function?
- How to get correct value from checked()?
- Prevent custom field from being updated after first publish
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Programmatically add Yoast meta description after post save
- Insert Address fields into function
- How to make custom comment fields required
- How add body_class from wp_termmeta
- How do I display a date correctly that is stored in the database as a backwards 8 digit number from Advanced Custom Fields? [closed]
- Sort and display pages with specific custom field (not tag)
- shorthand syntax for custom fields
- Fill empty custom field with other custom field
- Perform function on publish AND save (not just save)
- How to Display WooCommerce Product Price in WooCommerce Archive
- How to change text color depending on the number value (Using javascript)
- wp_set_object_term via js btn frontend
- Populate Product Regular Price with a calculated ACF Field Value
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Create New User Custom Field not Saving
- Creating a “Related Meta” type field?
- How would I correctly implement a new if statement in a child functions file?
- Hide empty custom field
- How To Show Shortcodes In WordPress Custom Fields?
- How to echo the translated custom field?
- How to add function to custom fields when page/post has a password?
- How to exclude posts with empty and non-existent relational custom field with meta_query?
- Post date on Custom field
- Dynamically generated Navigation Diagram using Custom Fields
- Define an extra field for all pages (with no plugin?)
- update_post_meta not working in function
- Adding custom field in menu options [duplicate]
- How to display data from custom fields in my custom shortcode?
- Syling Custom Fields echo’s from from functions.php
- Add custom fields after post/page title
- Adding and updating repeating custom field meta data
- Change Post status based on custom field date +1 day
- How to check if a user exists by a given id
- Define custom Page Template without its own .php file
- Perform an action when post is updated/published
- Sort posts by Date (DESC) and by Title (ASC)
- Remove a menu item created by a plugin
- Pagination adding page-numbers dots when using ‘mid_size’ => 0
- How to remove row-actions from pages table?
- Using wp_get_nav_menu_items() to list children of children pages
- Add new user : make the fields First Name and Last name required
- How to use PHPmailer in a function in WordPress
- wp_is_mobile function
- Get user id from email?
- Custom menus displaying all pages instead of set pages
- How Can I Access a PHP Variable in Another PHP Function
- How to fix a theme with page.php Default Template that accidentally deleted?
- Theme Demo in live Site
- WordPress – thumbnail image from youtube (function and loop)
- Problem with extract() with custom shortcode
- Change a sidebar name?
- Removing title from page
- CSS stylesheet not loading
- How To Get WordPress Categories Link List?
- How to add a predefined custom field without using a plugin?
- Generate permalinks
- Best Practice for Syncing Local Development With Staging Development [closed]
- Still relevant method of embedding images in WP Theme in 2018
- How can I create a page with a specific URL?
- When using wp_enqueue_script(); in a theme why don’t we use add_action?
- How does this function get the id of the most recent post?
- Batch update menu_order attribute alphabetically
- How to create function from code?
- How to use Internationalized human_time_diff() function in Chinese?
- Automatically wrap multiple images in div
- Ajax not working properly
- create shortcode to list users with specific meta key value
- How to add ‘data-caption’ inside an anchor tag
- How can I get my Script to work on the Login page?
- Execute a ultimate member action when user role is updated
- Search filter by Post title OR Meta Title Value [duplicate]
- Why is functions.php file in child not initializing and over-writing parent?
- Creating new blog on multisite programatically without hacks?
- Allowing users to view private posts (pending approval)