If I understand what you want I would call it on the save_post hook:
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
So the code would be something a little like:
function wphuyeh8_save_post_tag( $post_id, $post, $update ) {
// If example is set and not false
if($_REQUEST['_example']):
// set the tag
wp_set_post_tags( $post_ID, 'example', true );
else:
// remove the tag if the checkbox is not checked
wp_remove_object_terms( $post_id, 'example', 'post_tag' );
endif;
}
add_action( 'save_post', 'wphuyeh8_save_post_tag', 10, 3 );
Though this is untested, and taking a second glance it will try and remove the tag on every post save unless it is checked so you may want to add in some checking for a post type or something.
Related Posts:
- Remove tag on my RSS Feed
- get_the_excerpt() not returning anything when post has no excerpt
- Automatically add author’s name to post_tag
- Adding a class to tag list in a function
- Create single.php for specific tag by tag id or name
- list tags with count in author profile page
- Product Tags in Add New product as checkbox list [closed]
- Retrieve tags data in post body
- Echo tags used to describe the theme
- Frontend tag edit/submit form
- Is possible add icon in title posts only in specific tag?
- Display tags that only appear in one category
- Add a unique class to HTML tag/element
- How to edit the Tags within the image file URLs?
- Function filter breaking tag archive menus
- Tags break custom Excerpt function
- Numbering lines of code with the tag?
- Randomizing wp_tag_cloud() in child theme
- Sort and display pages with specific custom field (not tag)
- Function to echo (or display?) wordpress tags in the head section
- What is wp_get_post_tags for media tags?
- Allow user only create specific tags
- Removing sanitize_title_with_dashes Function with The Real Title
- method to fetch entire tag list on archive.php
- require_once() Causing categories and tag pages on dashboard to not refrsh
- Change post count on tag/terms pages to 10
- Custom taxonomy not refreshing page on add
- getExcerpt: Make ellipsis appear only if character limit is reached
- Make WordPress search for only this tags or exclude certain tags from search [duplicate]
- How to get tags and categories?
- If two tags in the middle i need comma
- Display function from functions.php in tag.php
- Bulk set Post Title as Tag where Tag is Empty Function
- wp_enqueue_script was called incorrectly
- Add multiple custom fields to the general settings page
- Prevent “main” WPMU site_url() being returned in functions
- How to redirect to post if search results only returns one post
- bloginfo() vs get_option?
- Get recent posts with thumbnail
- Display Total Number of Social Shares
- how to create shortcode in wordpress
- Function returns different value when called from ‘save_post’ than when called on page load
- add sidebar area to header of child theme
- Displaying a random user with a shortcode
- Assign category using custom field?
- Display a function using AJAX
- Hide the Private prefix on one specific page
- Updating users_can_register option?
- img width and height attributes being set by get_the_post_thumbnail
- How to properly add NPM packages and integrate them in WordPress?
- How to remove tag cloud from taxonomy admin edit page?
- echo get_post_meta()
- Custom function in My Custom Functions returning 403
- Remove H1 / title / Underscore – without CSS
- Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function now working
- functions.php How to add css/js depending on Template Name?
- How do you publish a draft on WordPress
- Show Primary Category first when I display post categories
- Wp_query function to search from product_title ‘OR’ product tags name
- Add other social networks to TwentyNineteen_SVG_Icons class in child theme?
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- wp_get_archives custom function broken since upgrading to WP 3.7.1
- Accessing two databases wordpress
- Add a jQuery Function
- How to get correct value from checked()?
- Redefine function arguments before rendering
- How do I change a parent theme’s function through the child theme?
- Enqueue script on every page except one
- Best way to handle lack of titles in microblogging
- Functions php shortcode for displaying main menu with no child items
- Redirect to other page if login
- first paragraph of the_content as meta description
- get_terms (or tax_query) for term of current post?
- 404 when enqueue_script using plugin_url
- How to use get_posts() function in functions.php
- How Can I add a menu to the theme from withen the function.php file
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Use a filter for wp_robots to block CPT/feed/
- Trigger email alert if file downloaded
- Completely Disable WordPress RSS Feeds
- How to hide content on mobile in the functions.php file – woocommerce
- WordPress Lite/Light
- Selecting specific query for offset
- Is_Page doesnt detect my page
- Show image after X para – center aligned
- Problems adding a new field to product in cart
- function replace_text for entire page
- Only Show One Category Name Per Post
- Quicktags external functions file
- Problem in shortcode outputting content
- Why does modifying my functions.php file always result in a server error
- Echo custom field value in shortcode function
- WordPress Comment functions
- wp_get_current_user->user login returns %20 for spaces
- Disable every rss feed except home feed
- reusing code in function and running it with loop
- Explode Array from Repeatable Custom Field
- Automatically delete posts that aren’t in an array
- Ads Only at one website inside multisite network – code error