Fluid Typography - Font Clamp Calculator
Font Clamp Calculator V4
Settings
Font Size Classes
| Class Name | Min Size | Max Size | Line Height |
|---|
Preview
Selected Class CSS
Generated CSS (All Classes)
Edit Font Size Class
[Fluid_calc]
| Class Name | Min Size | Max Size | Line Height |
|---|
Last Updated Wednesday 17th July 2024
Code Snippets Bundle
The Bundle contains 22 Snippets that improve Performance of your website, and add Admin Controls. You can import them all in one go rather than copying and pasting individually.
You will need the Free Code Snippets Plugin.
Before adding New Snippets
Click to download the Bundle OR Scroll down to see each individual snippet and add individually.
1) Unzip the File.
2) Go to WordPress Dashboard > Snippets > Import
3) The snippets will be added in ‘Deactivated’ form so you can manually activate them depending on your choice.
Go to Upload Files, and choose the unzipped file: elementor.code-snippets.json
Click the ‘Upload files and import’
If you are adding the Bundle again after it’s been updated with new snippets, then select the 3rd option to not import any duplicate snippets.
Then go to All Snippets and decide on which Snippets to Activate.
Activate and check one at a time.
add_action( 'init', 'add_categories_to_pages' );
/*
* Add CATEGORIES to pages
*/
function add_categories_to_pages() {
register_taxonomy_for_object_type( 'category', 'page' );
}
// Add the Contrast Checker Menu
add_action('admin_menu', 'contrast_checker_menu');
add_action('admin_init', 'contrast_checker_settings');
function contrast_checker_menu() {
add_options_page('Contrast Checker', 'Contrast Checker', 'manage_options', 'contrast-checker', 'contrast_checker_page');
}
function contrast_checker_settings() {
add_settings_section('contrast_checker_section', 'Contrast Checker Settings', null, 'contrast-checker');
add_settings_field('background_color', 'Background Color', 'background_color_callback', 'contrast-checker', 'contrast_checker_section');
add_settings_field('text_color', 'Foreground Color', 'foreground_color_callback', 'contrast-checker', 'contrast_checker_section');
register_setting('contrast_checker_group', 'background_color');
register_setting('contrast_checker_group', 'text_color');
}
function background_color_callback() {
$background_color = get_option('background_color', '#FFFFFF');
echo '';
echo '' . esc_attr($background_color) . '';
}
function foreground_color_callback() {
$foreground_color = get_option('text_color', '#000000');
echo '';
echo '' . esc_attr($foreground_color) . '';
}
function contrast_checker_page() {
?>
Contrast Checker
What is AA?
AA compliance refers to the Web Content Accessibility Guidelines (WCAG) 2.1, which require a contrast ratio of at least 4.5:1 for normal text (minimum 16px) and 3:1 for large text (minimum 24px or 19px bold). This ensures that content is readable and accessible for individuals with moderate visual impairments.
What is AAA?
AAA compliance is the highest level of conformance in WCAG 2.1. It requires a contrast ratio of at least 7:1 for normal text (minimum 16px) and 4.5:1 for large text (minimum 24px or 19px bold). Achieving AAA compliance ensures that content is accessible to the widest range of users, including those with significant visual impairments.
= 4.5) ? 'Yes' : 'No';
$aaa_pass = ($contrast_ratio >= 7) ? 'Yes' : 'No';
$suggested_aa = adjust_foreground_color($bg_rgb, $txt_rgb, 4.5);
$suggested_aaa = adjust_foreground_color($bg_rgb, $txt_rgb, 7);
return '
Contrast Ratio: ' . round($contrast_ratio, 2) . '
AA Compliant: ' . $aa_pass . '
AAA Compliant: ' . $aaa_pass . '
Suggested Foreground Color for AA:
' . $suggested_aa . '
Suggested Foreground Color for AAA:
' . $suggested_aaa . '
';
}
function hex_to_rgb($hex) {
$hex = ltrim($hex, '#');
$r = hexdec(substr($hex, 0, 2)) / 255;
$g = hexdec(substr($hex, 2, 2)) / 255;
$b = hexdec(substr($hex, 4, 2)) / 255;
return array($r, $g, $b);
}
function rgb_to_hex($rgb) {
return sprintf("#%02x%02x%02x", round($rgb[0] * 255), round($rgb[1] * 255), round($rgb[2] * 255));
}
function luminance($rgb) {
list($r, $g, $b) = $rgb;
$r = ($r <= 0.03928) ? $r / 12.92 : pow(($r + 0.055) / 1.055, 2.4);
$g = ($g <= 0.03928) ? $g / 12.92 : pow(($g + 0.055) / 1.055, 2.4);
$b = ($b <= 0.03928) ? $b / 12.92 : pow(($b + 0.055) / 1.055, 2.4);
return 0.2126 * $r + 0.7152 * $g + 0.0722 * $b;
}
function contrast_ratio($l1, $l2) {
$lighter = max($l1, $l2);
$darker = min($l1, $l2);
return ($lighter + 0.05) / ($darker + 0.05);
}
function adjust_foreground_color($bg_rgb, $txt_rgb, $target_ratio) {
$bg_luminance = luminance($bg_rgb);
$step = 0.02; // Adjust step value for precision and performance
// Incrementally adjust the RGB values to find a compliant color
for ($i = 0; $i <= 1; $i += $step) {
$test_rgb = adjust_rgb_lightness($txt_rgb, $i);
$test_luminance = luminance($test_rgb);
if (contrast_ratio($test_luminance, $bg_luminance) >= $target_ratio) {
return rgb_to_hex($test_rgb);
}
$test_rgb = adjust_rgb_lightness($txt_rgb, -$i);
$test_luminance = luminance($test_rgb);
if (contrast_ratio($test_luminance, $bg_luminance) >= $target_ratio) {
return rgb_to_hex($test_rgb);
}
}
return "#000000"; // fallback to black if no suitable color found
}
function adjust_rgb_lightness($rgb, $adjustment) {
return array(
min(1, max(0, $rgb[0] + $adjustment)),
min(1, max(0, $rgb[1] + $adjustment)),
min(1, max(0, $rgb[2] + $adjustment))
);
}
// Disable user registration
add_filter('pre_option_users_can_register', '__return_zero');
/**
* Duplicate WordPress Posts, Pages, and Custom Post Types as Drafts
*
* This code snippet enables the duplication of WordPress posts, pages, and all registered custom post types (CPTs).
* It adds a 'Duplicate' link to the row actions for each item in the admin dashboard. When clicked, this link
* triggers the duplication of the selected item, creating a new draft with the same content, custom fields,
* and taxonomies.
*
* Functions:
* 1. `duplicate_post_as_draft`: Handles the duplication process. It copies the post data, including title,
* content, excerpt, and custom fields, and creates a new post with a 'draft' status. It also maintains
* the taxonomy terms (like categories and tags) from the original post.
* 2. `duplicate_post_link`: Adds the 'Duplicate' action link to the WordPress admin interface for each post,
* page, and custom post type. This link uses WordPress's built-in nonce functionality for security.
* 3. `apply_duplicate_post_link_to_cpts`: Dynamically applies the duplicate post link function to all public
* post types, ensuring the 'Duplicate' link appears for any custom post types registered on the site.
*
* Author: Mark Harris
* URI: https://www.christchurchwebsolutions.co.uk
*/
function duplicate_post_as_draft() {
global $wpdb;
// Verify the nonce for security
$nonce_action = 'duplicate_post_as_draft';
$nonce_name = 'duplicate_nonce';
if (!isset($_GET[$nonce_name]) || !wp_verify_nonce($_GET[$nonce_name], $nonce_action)) {
wp_die(esc_html__('Security check failed.', 'wpturbo'));
}
// Check if the 'post' parameter is set in either GET or POST request
$post_id = filter_input(INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT) ?: filter_input(INPUT_POST, 'post', FILTER_SANITIZE_NUMBER_INT);
if (!$post_id) {
wp_die(esc_html__('No post to duplicate has been supplied!', 'wpturbo'));
}
// Check if the post exists
$post = get_post($post_id);
if (!$post) {
wp_die(esc_html(sprintf(__('Post creation failed, could not find original post: %s', 'wpturbo'), $post_id)));
}
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
$args = [
"comment_status" => $post->comment_status,
"ping_status" => $post->ping_status,
"post_author" => $new_post_author,
"post_content" => $post->post_content,
"post_excerpt" => $post->post_excerpt,
"post_name" => $post->post_name,
"post_parent" => $post->post_parent,
"post_password" => $post->post_password,
"post_status" => "draft",
"post_title" => $post->post_title . " (Copy)",
"post_type" => $post->post_type,
"to_ping" => $post->to_ping,
"menu_order" => $post->menu_order
];
$new_post_id = wp_insert_post($args);
$taxonomies = get_object_taxonomies($post->post_type);
foreach ($taxonomies as $taxonomy) {
$post_terms = wp_get_object_terms($post_id, $taxonomy, ["fields" => "slugs"]);
wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
}
$post_meta_infos = $wpdb->get_results(
$wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d", $post_id)
);
if (count($post_meta_infos) != 0) {
foreach ($post_meta_infos as $meta_info) {
$meta_key = $meta_info->meta_key;
$meta_value = sanitize_meta($meta_info->meta_key, $meta_info->meta_value, "post");
$wpdb->insert($wpdb->postmeta, [
"post_id" => $new_post_id,
"meta_key" => $meta_key,
"meta_value" => $meta_value
]);
}
}
// Redirect to the post list screen and show a success message
$redirect_url = admin_url("edit.php?post_type=" . $post->post_type);
wp_redirect(add_query_arg("message", "101", $redirect_url));
exit();
}
add_action("admin_action_duplicate_post_as_draft", "duplicate_post_as_draft");
function duplicate_post_link($actions, $post) {
if (current_user_can('edit_posts')) {
$actions['duplicate'] = 'ID),
'duplicate_post_as_draft',
'duplicate_nonce'
) .
'" title="' . esc_attr__('Duplicate this item', 'wpturbo') .
'" rel="permalink">' . esc_html__('Duplicate', 'wpturbo') . '';
}
return $actions;
}
add_filter("post_row_actions", "duplicate_post_link", 10, 2);
add_filter("page_row_actions", "duplicate_post_link", 10, 2);
function apply_duplicate_post_link_to_cpts() {
$post_types = get_post_types(["public" => true], "names");
foreach ($post_types as $post_type) {
add_filter("{$post_type}_row_actions", "duplicate_post_link", 10, 2);
}
}
add_action("admin_init", "apply_duplicate_post_link_to_cpts");
function show_duplicate_admin_notice() {
if (isset($_GET['message']) && $_GET['message'] === '101') {
echo '' . esc_html('Post duplicated successfully.') . '
';
}
}
add_action('admin_notices', 'show_duplicate_admin_notice');
// Function to add the calculator to the admin menu
function ft_calculator_admin_menu()
{
add_menu_page(
"Fluid Typography Calculator", // Page title
"Clamp Calculator", // Menu title
"manage_options", // Capability
"fluid-typography-calculator", // Menu slug
"ft_calculator_page" // Function that displays the page content
);
}
add_action("admin_menu", "ft_calculator_admin_menu");
// Function that generates the calculator page
function ft_calculator_page() {
// Initialize the $useRem variable at the start of the function
$useRem = false;
echo 'Fluid Typography Calculator
';
// Basic styles for the form and output
echo '';
// Initialize variables
$rootFontSize = isset($_POST["rootFontSize"]) ? $_POST["rootFontSize"] : 16;
$defaultValues = [
"h1" => [
"MinWidth" => 380,
"MinFontSize" => 29,
"MaxWidth" => 1600,
"MaxFontSize" => 68,
],
"h2" => [
"MinWidth" => 380,
"MinFontSize" => 24,
"MaxWidth" => 1600,
"MaxFontSize" => 51,
],
"h3" => [
"MinWidth" => 380,
"MinFontSize" => 20,
"MaxWidth" => 1600,
"MaxFontSize" => 38,
],
"h4" => [
"MinWidth" => 380,
"MinFontSize" => 17,
"MaxWidth" => 1600,
"MaxFontSize" => 29,
],
"h5" => [
"MinWidth" => 380,
"MinFontSize" => 14,
"MaxWidth" => 1600,
"MaxFontSize" => 22,
],
"h6" => [
"MinWidth" => 380,
"MinFontSize" => 12,
"MaxWidth" => 1600,
"MaxFontSize" => 16,
],
"body" => [
"MinWidth" => 380,
"MinFontSize" => 16,
"MaxWidth" => 1600,
"MaxFontSize" => 24,
],
"p" => [
"MinWidth" => 380,
"MinFontSize" => 16,
"MaxWidth" => 1600,
"MaxFontSize" => 24,
],
];
$cssOutput = ""; // Initialize traditional CSS output string
$cssVariablesOutput = ""; // Initialize CSS variables output string
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$useRem = isset($_POST["unitToggle"]) && $_POST["unitToggle"] === 'on';
// Security check using nonce
if (!isset($_POST["ft_calculator_nonce_field"]) || !wp_verify_nonce($_POST["ft_calculator_nonce_field"], "ft_calculator_action")) {
echo "Security check failed. Please try again.
";
return;
}
foreach (["h1", "h2", "h3", "h4", "h5", "h6", "body", "p"] as $tag) {
$minWidth = $_POST[$tag . "MinWidth"]; // In pixels
$minFontSizePx = $_POST[$tag . "MinFontSize"]; // In pixels or REM based on $useRem
$maxWidth = $_POST[$tag . "MaxWidth"]; // In pixels
$maxFontSizePx = $_POST[$tag . "MaxFontSize"]; // In pixels or REM based on $useRem
// Handle unit conversion
if ($useRem) {
// Convert REM to Pixels for internal calculation
$minFontSizePx *= $rootFontSize;
$maxFontSizePx *= $rootFontSize;
}
// Convert pixel values to REM for CSS generation
$minFontSize = $minFontSizePx / $rootFontSize; // In rem
$maxFontSize = $maxFontSizePx / $rootFontSize; // In rem
// Convert widths from px to vw (assuming 1rem = rootFontSize px)
$minWidthVW = $minWidth / $rootFontSize; // In vw
$maxWidthVW = $maxWidth / $rootFontSize; // In vw
// Calculate the CSS
$vwUnit =
(($maxFontSize - $minFontSize) / ($maxWidthVW - $minWidthVW)) *
100;
$constant = $minFontSize - ($vwUnit * $minWidthVW) / 100;
// Format to a maximum of 5 decimal places
$vwUnitFormatted = number_format($vwUnit, 5, ".", "");
$constantFormatted = number_format($constant, 5, ".", "");
// Add to traditional CSS output
$cssOutput .=
"{$tag} {font-size: clamp(" .
$minFontSize .
"rem, " .
$constantFormatted .
"rem + " .
$vwUnitFormatted .
"vw, " .
$maxFontSize .
"rem);}\n";
// Add to CSS variables output
$cssVariablesOutput .=
" --{$tag}-font-size: clamp(" .
$minFontSize .
"rem, " .
$constantFormatted .
"rem + " .
$vwUnitFormatted .
"vw, " .
$maxFontSize .
"rem);\n";
}
// Wrap CSS variables in a :root selector
$cssVariablesOutput = ":root {\n" . $cssVariablesOutput . "}\n";
}
// Display the form
echo '';
// Display the traditional CSS output
if (!empty($cssOutput)) {
echo "Generated CSS:
";
echo '
";
echo '';
}
// Display the CSS variables output
if (!empty($cssVariablesOutput)) {
echo "Generated CSS Variables:
";
echo '
";
echo '';
}
// JavaScript for copy to clipboard functionality and unit conversion
echo '';
echo "";
}
// Define the function for the fluid typography calculator
function fluid_typography_calculator() {
// Call the existing function to display the fluid typography calculator
ft_calculator_page();
}
// Add the shortcode
add_shortcode('Fluid_calc', 'fluid_typography_calculator');
add_filter( 'media_library_infinite_scrolling', '__return_true' );
function custom_mime_types($mimes) {
$mimes['woff'] = 'font/woff';
$mimes['woff2'] = 'font/woff2';
return $mimes;
}
add_filter('upload_mimes', 'custom_mime_types');
function limit_image_sizes($sizes) {
// Keep only the thumbnail size
return array(
'thumbnail' => $sizes['thumbnail']
);
}
add_filter('intermediate_image_sizes_advanced', 'limit_image_sizes');
function set_thumbnail_size() {
// Set the thumbnail size to 150x150
update_option('thumbnail_size_w', 150);
update_option('thumbnail_size_h', 150);
update_option('thumbnail_crop', 1); // 1 for hard crop, 0 for soft crop
}
add_action('admin_init', 'set_thumbnail_size');
// Remove the unnecessary regenerate_thumbnails function as the thumbnail is already handled
function restrict_plugins_page() {
// Check if the current user is trying to access the Plugins page
global $pagenow;
if ($pagenow === 'plugins.php' || strpos($_SERVER['REQUEST_URI'], 'plugin-install.php') !== false || strpos($_SERVER['REQUEST_URI'], 'plugin-editor.php') !== false) {
// Start a session if not already started
if (!session_id()) {
session_start();
}
// SET THE PASSWORD HERE !!
$required_password = '123'; // Change this to your desired password
// Check if the password has been submitted and is correct
if (isset($_POST['plugins_password']) && $_POST['plugins_password'] === $required_password) {
$_SESSION['plugins_access_granted'] = true;
}
// Check if the session variable is not set, meaning access is not granted
if (empty($_SESSION['plugins_access_granted'])) {
// Display the password form
echo ' ';
// Prevent the rest of the Plugins page from loading
exit;
}
}
}
add_action('admin_init', 'restrict_plugins_page');
function restrict_settings_page() {
// Check if the current user is trying to access the Settings page
global $pagenow;
$settings_pages = array(
'options-general.php',
'options-writing.php',
'options-reading.php',
'options-discussion.php',
'options-media.php',
'options-permalink.php',
// Add more settings pages if you have plugins that add their own settings
);
if (in_array($pagenow, $settings_pages)) {
// Start a session if not already started
if (!session_id()) {
session_start();
}
// Set the password
$required_password = '123'; // Change this to your desired password
// Check if the password has been submitted and is correct
if (isset($_POST['settings_password']) && $_POST['settings_password'] === $required_password) {
$_SESSION['settings_access_granted'] = true;
}
// Check if the session variable is not set, meaning access is not granted
if (empty($_SESSION['settings_access_granted'])) {
// Display the password form
echo ' ';
// Prevent the rest of the Settings page from loading
exit;
}
}
}
add_action('admin_init', 'restrict_settings_page');
if (!function_exists('restrict_snippets_pages')) {
function restrict_snippets_pages() {
// Check if the current user is trying to access the Snippets pages
global $pagenow;
$restricted_pages = array(
'admin.php?page=snippets',
'admin.php?page=snippet-manager',
'admin.php?page=snippet-import',
'admin.php?page=add-snippet',
'admin.php?page=import-code-snippets'
);
// Check if the current request URI contains any of the restricted pages
$is_restricted_page = false;
foreach ($restricted_pages as $restricted_page) {
if (strpos($_SERVER['REQUEST_URI'], $restricted_page) !== false) {
$is_restricted_page = true;
break;
}
}
if ($is_restricted_page) {
// Start a session if not already started
if (!session_id()) {
session_start();
}
// SET THE PASSWORD HERE !!
$required_password = '123'; // Change this to your desired password
// Check if the password has been submitted and is correct
if (isset($_POST['snippets_password']) && $_POST['snippets_password'] === $required_password) {
$_SESSION['snippets_access_granted'] = true;
}
// Check if the session variable is not set, meaning access is not granted
if (empty($_SESSION['snippets_access_granted'])) {
// Display the password form
echo ' ';
// Prevent the rest of the Snippets page from loading
exit;
}
}
}
add_action('admin_init', 'restrict_snippets_pages');
}
function restrict_users_page() {
// Check if the current user is trying to access the Users page
global $pagenow;
if ($pagenow === 'users.php' || $pagenow === 'user-new.php' || $pagenow === 'profile.php') {
// Start a session if not already started
if (!session_id()) {
session_start();
}
// Set the password
$required_password = '123'; // Change this to your desired password
// Check if the password has been submitted and is correct
if (isset($_POST['users_password']) && $_POST['users_password'] === $required_password) {
$_SESSION['users_access_granted'] = true;
}
// Check if the session variable is not set, meaning access is not granted
if (empty($_SESSION['users_access_granted'])) {
// Display the password form
echo ' ';
// Prevent the rest of the Users page from loading
exit;
}
}
}
add_action('admin_init', 'restrict_users_page');
if ( ! function_exists( 'custom_set_permalink_structure_to_post_name' ) ) {
/**
* Sets the default permalink structure to 'Post Name' if it is not already set.
*
* To change the default permalink structure, update the `$desired_permalink_structure`
* variable with one of the following values:
*
* - Plain: ''
* - Day and Name: '/%year%/%monthnum%/%day%/%postname%/'
* - Month and Name: '/%year%/%monthnum%/%postname%/'
* - Numeric: '/%post_id%/'
* - Post Name: '/%postname%/'
* - Custom Structure: '/your/custom/structure/'
*/
function custom_set_permalink_structure_to_post_name() {
// Get the current permalink structure
$current_permalink_structure = get_option('permalink_structure');
// Set the desired permalink structure here
// Default is 'Post Name'
$desired_permalink_structure = '/%postname%/';
// Uncomment one of the following lines to set a different permalink structure
// Plain:
// $desired_permalink_structure = '';
// Day and Name:
// $desired_permalink_structure = '/%year%/%monthnum%/%day%/%postname%/';
// Month and Name:
// $desired_permalink_structure = '/%year%/%monthnum%/%postname%/';
// Numeric:
// $desired_permalink_structure = '/%post_id%/';
// Custom Structure:
// $desired_permalink_structure = '/your/custom/structure/';
// Check if the current structure is not already set to the desired structure
if ($current_permalink_structure != $desired_permalink_structure) {
// Update the permalink structure
update_option('permalink_structure', $desired_permalink_structure);
// Flush rewrite rules to apply the new permalink structure
flush_rewrite_rules();
}
}
add_action('admin_init', 'custom_set_permalink_structure_to_post_name');
}
/*
Plugin Name: Purge Cache
Description: Adds a button to the WordPress dashboard to clear the object cache
*/
add_action( 'admin_bar_menu', 'add_purge_cache_button', 999 );
function add_purge_cache_button( $wp_admin_bar ) {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$args = array(
'id' => 'purge-cache',
'title' => 'Purge Cache',
'href' => '#',
'meta' => array( 'class' => 'purge-cache' )
);
$wp_admin_bar->add_node( $args );
}
add_action( 'admin_footer', 'add_purge_cache_script' );
function add_purge_cache_script() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
?>
/*
Comments in WordPress are like an open mic.
Sometimes you want to turn the mic off.
Silencing the comment section might just be your ticket to serenity.*/
function codesnippets_disable_comments() {
// Remove comment support for posts
remove_post_type_support( 'post', 'comments' );
// Remove comment support for pages
remove_post_type_support( 'page', 'comments' );
// Remove comments from the admin menu
remove_menu_page( 'edit-comments.php' );
// Redirect comment-related URLs to the homepage
add_action( 'template_redirect', 'codesnippets_disable_comments_redirect' );
}
function codesnippets_disable_comments_redirect() {
global $wp_query;
if ( is_single() || is_page() || is_attachment() ) {
if ( have_comments() || comments_open() ) {
wp_redirect( home_url(), 301 );
exit;
}
}
}
add_action( 'admin_init', 'codesnippets_disable_comments' );
function remove_dashboard_widgets() {
remove_action( 'welcome_panel', 'wp_welcome_panel' );
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' );
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' );
remove_meta_box( 'e-dashboard-overview', 'dashboard', 'normal' );
}
add_action( 'wp_dashboard_setup', 'remove_dashboard_widgets' );
add_action('save_post', function ($post_id, $post, $update) {
// Check if the post is an instance of Elementor's Kit
if ('elementor_library' === get_post_type($post_id) && 'kit' === get_post_meta($post_id, '_elementor_template_type', true)) {
$meta = get_post_meta($post_id, '_elementor_page_settings', true);
// Handle custom colors
if (!empty($meta['custom_colors'])) {
foreach ($meta['custom_colors'] as &$custom_color) {
// Replace the hyphens inside of titles with underscores to ensure consistency
$custom_color['_id'] = str_replace('-', '_', sanitize_title($custom_color['title']));
}
}
// Update post meta
update_post_meta($post_id, '_elementor_page_settings', $meta);
}
}, 10, 3);
define('WP_POST_REVISIONS', 3);
This comes in 3 parts.
Part 1: The HTML
Part 2: The Snippet
add_action('wp_head', 'dark_mode_toggle_script');
function dark_mode_toggle_script() {
?>
Part 3: Example CSS
html { font-size: 100%; } /* Default is always 16px */
/* Text */
h1 {
font-size: clamp(2.5rem, 1.75rem + 3vw, 4rem);
font-weight: 900;
color: var(--e-global-color-primary);
}
.darkMode h1 {
color: #FFF;
}
h2 {
font-size: 2rem;
font-weight: 600;
color: var(--e-global-color-secondary);
}
.darkMode h2 {
color: #D0D0CE;
}
.purple h2 {
font-size: 1.5rem;
font-weight: 900;
color: var(--e-global-color-purple_shade);
}
.darkMode .purple h2 {
color: var(--e-global-color-dark_mode_yellow);
}
p {
font-size: clamp(1rem, 0.875rem + 0.5vw, 1.25rem);
font-weight: normal;
color: var(--e-global-color-text);
}
.darkMode p {
color: var(--e-global-color-white);
}
/* Backgrounds */
body {
background-color: #FFF; /* Light background */
}
.darkMode {
background-color: #000; /* Dark background */
}
.hero_banner {
background-color: #EFEFEF;
}
.darkMode .hero_banner {
background-color: #222222;
}
/* Buttons */
.elementor-button {
background-color: var(--e-global-color-primary);
color: #FFF;
}
.elementor-button:hover {
background-color: #000;
}
.darkMode .elementor-button {
background-color: #F3F3F3;
color: #000;
}
.darkMode .purple_shade .elementor-button {
background-color: var(--e-global-color-dark_mode_yellow);
color: #000;
}
/* Applied to Menu */
.elementor-nav-menu a {
color: #000;
}
.darkMode .elementor-nav-menu a {
color: var(--e-global-color-dark_mode_yellow);
}
/* Images */
.darkMode img {
filter: brightness(0.7) contrast(1.1);
}
.darkMode .grayscale img {
filter: grayscale(1); /* Between 0 and 1 */
}
.darkMode .saturate img {
filter: saturate(1.5); /* 1+ increase, <1 decrease */
}
.darkMode .sepia img {
filter: sepia(1); /* Between 0 and 1 */
}
/* SVG Icons */
.elementor-icon svg {
fill: #000;
}
.darkMode .elementor-icon svg {
fill: var(--e-global-color-dark_mode_yellow);
}
add_filter( 'elementor_pro/custom_fonts/font_display', function( $current_value, $font_family, $data ) {
return 'swap';
}, 10, 3 );
add_filter( 'elementor/frontend/print_google_fonts', '__return_false' );
/**
* We will Dequeue the jQuery UI script as example.
*
* Hooked to the wp_print_scripts action, with a late priority (99),
* so that it is after the script was enqueued.
*/
function wp_remove_scripts() {
// check if user is admin
if (current_user_can( 'update_core' )) {
return;
}
else {
// Check for the page you want to target
if ( is_page( 'homepage' ) ) {
// Remove Scripts
wp_dequeue_style( 'jquery-ui-core' );
}
}
}
add_action( 'wp_enqueue_scripts', 'wp_remove_scripts', 99 );
add_filter( 'wp_lazy_loading_enabled', '__return_false' );
Last Updated Saturday 29 June 2024
WordPress General Settings
1) Set the Site Title (or go to WordPress Dashboard > Appearance > Customize).
2) Set the Site Icon (or go to WordPress Dashboard > Appearance > Customize).
3) Ensure the Address/Site URL both begin with https:// (If you don’t have a valid SSL Certificate, then check with your host).
4) Ensure the Admin Email Address is correct.
WordPress Reading Settings
This step can be left until a Homepage or a Landing Page has been created.
Return here to set the first page to be loaded when a user enters your parent domain.
WordPress Discussion Settings
The items here are subjective to if;
1) You permit comments to be added, and
2) You will moderate activity and remove spam.
Within the ‘Course’, we will advise on disabling Comments for particular Posts and Pages.
Inside of the ‘Settings Pack’, you will find the Snippets Bundle with a Code Snippet to fully disable comments on all Posts and Pages.
WordPress Media Settings
When images are added to the Media Library, multiple versions may be created in your wp-uploads folder.
1) Images should be uploaded as a webp format. We show how to convert PNG/JPEG within the ‘Course’.
2) Images should be reasonably sized to the maximum size required on the site. Do not upload an image that is 1920x 1080 if it will only be 300px wide on a site.
I leave the Thumbnail Size as 150×150, and set the others to be 0.
Inside of the ‘Settings Pack’, you will find the Snippets Bundle with a Code Snippet to ‘future-proof’ prevent duplicate images being created in your database.
WordPress Permalink Settings
Set the format of the links that will appear for Posts, Pages and Products.
I recommend ‘Post Name’ especially if you care about SEO and Keyword Marketing.
Inside of the ‘Settings Pack’, you will find the Snippets Bundle with a Code Snippet to set the Permalink to always stay set to prevent someone modifying it.