Whenever you use a value from an array, like $array['key'] where it’s possible that the 'key' doesn’t exist (such as the first time a widget is used) you need to check that it exists before using it or you’ll get errors on those occasions where it hasn’t been set.
Your problem is that when the widget’s first added 'tick_the_snippet_type' doesn’t exist on $instance, so you need to account for this possibility. I’d suggest creating a variable to pass to checked() which will either contain tick_the_snippet_type or a default if it doesn’t exist:
if ( isset( $instance['tick_the_snippet_type'] ) ) {
$value = $instance['tick_the_snippet_type'];
} else {
$value = false;
}
Which can be written on one line with a ternary operator:
$value = isset( $instance['tick_the_snippet_type'] ) ? $instance['tick_the_snippet_type'] : false;
And then use this for checked:
<?php checked( $value, 'tick_snippet_4' ); ?>
Related Posts:
- Shortcode putting html such as
- How to get the registered sidebar’s name by its id?
- display most popular tags in two columns
- “Can’t use function return value in write context” error
- WordPress menu deletes when trying to add a hook
- Get widget settings function?
- javaScript in section of WP API
- Add before_content and after_content to register_sidebar
- PHP Deprecated: WP_RSSjb has a deprecated constructor
- How to put a variable in a instance in the widget
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- Adding a widget function into the php theme file
- Widget back end radio button issue
- My website is not showing Footer section
- How to get post category list as select in front-end?
- Show different website layout if no sidebar added
- Add a select-option to the default widgets
- Programmatically revert to backup .htaccess a possibility?
- Can’t log in to WordPress wp-admin after adding code to functions.php
- How a HTML form can trigger a PHP function?
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- Site title not showing. Please help me
- is_user_logged_in() not working in homepage
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- Add disclaimer before certain posts and pages
- How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
- WordPress – registering sidebar and adding a button directly after .textwidget
- List sibling pages widget, exclude current page
- Functions are causing errors
- syntax error unexpected ‘}’ at 364 line
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- How to draw media details for Isotope gallery using Photoswipe
- WordPress “Link has expired” error on updating posts
- Remove wp-mediaelement.css from wp_head
- add_filter to post-gallery and remove all ‘s?
- Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
- Custom Widget outputs the input but doesn’t save anything inside the textarea
- delete an array element when its date expires
- Using a function written in my functions.php file within the header.php file
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- dynamic sidebar not showing anything
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- WordPress Redirect: Default Password Reset URL [duplicate]
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- How to remove or change the “W” icon in “My Sites”?
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- WordPress Script stops suddenly
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- foreach loop still echoes array
- dynamic dependent select dropdown
- Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
- getting logged in user info (wp-load.php) from parent directory
- wp-comments-post.php file returns a blank page
- Add .htm extention to a custom taxonomy
- php syntax : [ && ] between commands [closed]
- Which PHP page is the Default Posts Page
- meaning of (array)function()
- Need to put a script above tag in header.php – WP 5.7.1
- Sending a custom form data in email through WP Mail Function
- Isotope Drop Down Categories Filter Function
- How to use array in function to get only value I want
- How to add PHP code in functions.php wordpress
- add_filter function concatenate string and locate_template function
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- get_page_templates only return templates with “home” in the filename
- Nav-Menu not showing up
- How to pass hook variable to function?
- Migrating site, only header shows
- remove specificly the last tag in all posts
- Let current user know pending posts counts using wp_query
- How to check post meta isset or not empty during publish/save post?
- how to changes mobile menu toggle breakpoint in WordPress
- Get page permalink in contact form
- How to display already created menus via php?
- Grabbing Image name From Product Image Gallery
- Gutenberg block don’t save rich text content
- remove_action from parent theme using child theme functions.php
- Cant get blog name with get_option
- Remove span tags from WooCommerce Downloads page
- Extra editor on top of default in Custom Post Type
- How to add typehints to function in functions.php when argument is an object?
- Pagination 404 error(I have refreshed the permalinks and tried several previous options)
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- WordPress database error only while loading page for 1st time
- Featured Products not showing up in “Featured” area of homepage
- How can I include tags in wordpress search without a plugin
- How to set up an auto delete post?
- apply_filters() function
- Using tag to output text in Genesis?
- wp wp_register_script function results type parameter missing
- php “use” not working in template [closed]
- A next page function with shortcode?
- What is the wrong with this function to enqueue the scripts and styles to the theme? [closed]
- Warning: Attempt to read property “term_id” on int – Woocommerce
- Need help with conditional logic for menus
- Custom Admin Menu Report for Specific User ID
- how to create twitter card without plugin in wordpress website?
- check difference between two timestamp in custom plugin