Home / Admin / Set Background Color for Active Snippets (WPCode)
Duplicate Snippet

Embed Snippet on Your Site

Set Background Color for Active Snippets (WPCode)

This code snippet sets a background color and adds a vertical activation bar to the WPCode plugin table when a code snippet is activated, making it easy to identify which code snippets are active. The interface closely resembles — if not exactly matches — WordPress' admin plugins table.

Code Snippet Parameters:

1. Code Snippet Type: Universal.
2. Location: Admin header.
3. Device Type: Any device.

Credits: Marko (WPCode Developer) and Petar Dietrich (Omnia Aerospace, LLC)

Code Preview
universal
<style>
		#wpcode-code-snippets-table .wp-list-table tbody tr:has(.wpcode-status-toggle:checked) {
			background-color: #f0f6fc !important;
		}
		
		#wpcode-code-snippets-table .wp-list-table tbody tr.wpcode-active-row {
			background-color: #f0f6fc !important;
		}
		
		.wpcode-snippets th, .wpcode-snippets td {
   			border-bottom: .5px solid #c3c4c780;
		}
	
		#wpcode-code-snippets-table .wp-list-table tbody tr.wpcode-active-row .check-column {
			border-left: 4px solid #72aee6;
			padding-left: 3px!important;
		}	
	
		#wpcode-code-snippets-table .widefat tfoot td.check-column, .widefat thead td.check-column, .widefat tbody th.check-column {
			padding-left: 6px;
		}
</style>
<script>
		(function ($) {
			function markRows(ctx) {
				const $rows = $('#wpcode-code-snippets-table .wp-list-table tbody tr', ctx && ctx.length ? ctx : document);
				$rows.each(function () {
					const $tr = $(this);
					const isActive = $tr.find('.wpcode-status-toggle').is(':checked');
					$tr.toggleClass('wpcode-active-row', isActive);
				});
			}
			$(function () {
				// Initial pass on page load.
				markRows();
				// Update the row highlight when the status is toggled.
				$(document).on('change', '.wpcode-status-toggle', function () {
					const $tr = $(this).closest('tr');
					$tr.toggleClass('wpcode-active-row', $(this).is(':checked'));
				});
				// Re-run after the table is replaced by AJAX (filtering/pagination).
				const target = document.getElementById('wpcode-code-snippets-table');
				if (target && 'MutationObserver' in window) {
					const observer = new MutationObserver(function () {
						markRows();
					});
					observer.observe(target, { childList: true, subtree: true });
				}
			});
		})(jQuery);
</script>

Comments

Add a Comment