Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Allow iframe in custom meta box

I tried your code and it works:

I changed the wp_verify_nonce function, because that wasn’t working for me. I added an action instead of what it had. Now, for this to work, you have to create a nonce field with a code like this, of course that you can change the names if you want.

//this goes in the function that generates the metabox    
wp_nonce_field( 'location_map_nonce_action', 'location_map_nonce' );

And this is the finall code of the function that save the values.

function kk_save_location_map( $post_id, $post ) {



    /* Verify the nonce before proceeding. */
    if ( !isset( $_POST['location_map_nonce'] ) || !wp_verify_nonce( $_POST['location_map_nonce'], 'location_map_nonce_action' ) ){
            return $post_id;
     }

    /* Get the post type object. */
    $post_type = get_post_type_object( $post->post_type );

    /* Check if the current user has permission to edit the post. */
    if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ){

        return $post_id;
    }

    /* Get the posted data and sanitize it for use as an HTML class. */
    $new_meta_value = ( isset( $_POST['location-map'] ) ? ( $_POST['location-map'] ) : '' );

    /* Get the meta key. */
    $meta_key = 'location-map';

    /* Get the meta value of the custom field key. */
    $meta_value = esc_textarea(get_post_meta( $post_id, $meta_key, true ));

    /* If a new meta value was added and there was no previous value, add it. */
    if ( $new_meta_value && '' == $meta_value ){

        add_post_meta( $post_id, $meta_key, $new_meta_value, true );
    }
    /* If the new meta value does not match the old value, update it. */
    elseif ( $new_meta_value && $new_meta_value != $meta_value ){

        update_post_meta( $post_id, $meta_key, $new_meta_value );
    }
    /* If there is no new meta value but an old value exists, delete it. */
    elseif ( '' == $new_meta_value && $meta_value ){

        delete_post_meta( $post_id, $meta_key, $meta_value );
    }   

}

add_action( 'save_post', 'kk_save_location_map', 10, 2 );

Related Posts:

  1. esc before saving or before displaying does it matter?
  2. Passing error/warning messages from a meta box to “admin_notices”
  3. Add “upload media” button in meta box field
  4. get registered metaboxes by post type or post ID
  5. How to get meta box data to display on a page
  6. Add a meta description to home page?
  7. Check if meta key value already exists
  8. How do I stop HTML entities in a custom meta box from being un-htmlentitied?
  9. get_post_meta doesn’t work
  10. Metabox of one post influence setting on other
  11. How to store multiple input values with same meta_key
  12. Consolidate Metaboxes into 1 Big Metabox
  13. unable to save post meta on single field with multiple selects
  14. metabox upload file
  15. Why is variable value emptry in $_POST but available in $_REQUEST?
  16. Why does get_post_meta not work with the posts page?
  17. How to get meta box values – WP tuts tutorial
  18. Change the post date from a meta box
  19. update_post_meta and get_post_meta not working
  20. Repeatable custom meta fields
  21. metabox wordpress show in frontend
  22. how to save multiple checkboxes value in wordpress dynamically
  23. Using WYSIWYG In custom meta boxes
  24. Multiplicate entry on update_post_meta
  25. Undefined index error in custom post metabox
  26. Custom Meta box only returns most recent value on page
  27. How to prevent further updates of custom meta when using actions to set one meta based on another
  28. How to create a button click counter meta box?
  29. meta box & callback function
  30. $_GET & $post_ID
  31. get_post_meta as a list for drop down search filter
  32. Parse a text area custom meta box and assign as value to existing meta keys
  33. Getting metabox value?
  34. Hide Page Title with Post Meta
  35. Save meta data with post, Without using any plugin [closed]
  36. Editor meta box Showing but not saving
  37. How can i get multi checkboxes value in metbox?
  38. Show value of select dropdown in meta box
  39. remove a single post_meta
  40. Echo 2 values from one key in Array with get_post_custom
  41. save radio button selection in post-meta on submit
  42. post meta – problem : copy the same meta for all the articles
  43. Custom Meta Data is not being saved
  44. Update Post Meta in Front End with a form
  45. Update Post meta with custom variable
  46. get_post_meta not working on my custom-function page
  47. update_post_meta doesn’t work
  48. Removing Meta Generator
  49. Only allow one meta key value per post in a category
  50. use post meta in add_meta_boxes action
  51. Custom meta box not saving values of radio buttons in WordPress
  52. Can’t save drop down select date in meta boxes
  53. update_post_meta does not work
  54. add_post_meta not saved
  55. when saveing $meta_box i get Undefined index error
  56. Updating post meta and Meta Box plugin
  57. Related posts and custom meta_box?
  58. Select Options Meta Data is Not Updating in Edit Meta Box
  59. How to display meta box data using “Meta boxes as needed”
  60. Metadata in loops
  61. Calling Data from Custom Meta Box
  62. How can i remove blank area caused by theme’s post meta boxes?
  63. Datepicker altField and altFormat to save a new meta key/value in a post?
  64. My meta box don’t want to save value
  65. CPT posts in drop downed in meta box on page doesn’t return post ID
  66. Create more Meta Boxes as needed
  67. Set Default Admin Screen options & Metabox Order
  68. How to set default screen options?
  69. Add a Meta Box for uploading a SECOND Featured Image?
  70. Does WordPress have a “Form API”?
  71. Metabox with checkbox is not updating
  72. How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button
  73. What is the “Advanced” $context in add_meta_box?
  74. Removing panels (meta boxes) in the Block Editor
  75. Change The Title Of a Meta Box
  76. What is the index [0] for on post meta fields?
  77. WordPress SEO by Yoast: Hide Meta Boxes in Posts for Non-admins
  78. How to make open/closed and hidden/shown metaboxes status saved on a per-post basis?
  79. How To Remove The “+ Add New Category” Link From A Category Metabox
  80. How can I create a taxonomy meta-box with search suggestions but no new terms input?
  81. Remove the Featured Image Meta Box
  82. Remove the Yoast SEO Post Metabox [closed]
  83. Best practices for meta box placement?
  84. Creating a metabox to upload multiple images
  85. How Does WordPress Remember Metabox Positions?
  86. Sample code for validating custom metabox?
  87. Post custom metabox textarea using wp_editor
  88. How to Add Reminders/Notes to New Post Meta Boxes
  89. How do I get attachment_id?
  90. Removing Metabox for “Slug” without removing functionality
  91. post formats – how to switch meta boxes when changing format?
  92. How to reorder meta box position?
  93. Prevent sorting and dragging of specific postbox metabox
  94. One metabox for multiple post types
  95. How can I retrieve multiple get_post_meta values efficiently?
  96. How do I position meta_box on post edit screen after the title?
  97. How to add a class to meta box
  98. Custom field metabox not showing in back-end
  99. Has anyone successfully integrated qtranslate with custom metaboxes?
  100. Put the media uploader in a metabox
Categories metabox Tags escaping, iframe, metabox, post-meta
Carousel Loop only duplicating
How do I add and display a custom image field to a category? [duplicate]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress