Category: Snippets
-

WordPress – Handle theme.json HSL color transparency
WordPress’s full site editing capabilities have revolutionized theme customization, allowing for an extensive range of configurations through the theme.json file. However, one limitation has been the inability to handle color transparency effectively with traditional hexadecimal color codes. To address this, we’ve crafted a solution to enhance your theme’s color system. Find out how to do…
-

SCSS – Min-Max interpolation
Responsive design often requires fluid scaling of elements to fit different screen sizes. A typical use case is scaling typography, where font sizes should adjust between a minimum and maximum size based on the viewport/container-size. To facilitate this, we use min-max interpolation techniques. SCSS Helper Functions The SCSS code includes several functions designed to enable…
-

SCSS – Remove units from numbers
In the realm of CSS preprocessing, we often encounter situations where we need to perform calculations or pass values to functions that expect unitless numbers. However, numbers in CSS often come with units like pixels (px), ems (em), or percentages (%), which can be problematic in such cases. Introducing the strip-unit Function To address this…
-

SCSS – Internationalization of Quotation Marks
In written language, different cultures use different symbols to denote quotations. For instance, English typically uses “curly quotes,” while French favors «angle quotes», and German uses „bottom quotes“. Ensuring that the correct quotation marks appear based on the language of the text is an important detail for maintaining the authenticity and readability of multilingual content…
-

WordPress – How to remove default theme colors
Crafting a unique look and feel for your WordPress site often involves overriding the default color palettes, gradients, and typography sizes that come with the core or themes. The following PHP code snippet is designed to help you start with a clean slate by removing these defaults. The Code This snippet should be added to…
-

WordPress – Enhance Rest API security with Nonce
The WordPress REST API opens up a world of possibilities for developers by allowing programmatic interaction with site data. However, with this power comes the need for heightened security to ensure that only authorized requests are processed. The following PHP snippet demonstrates how to secure REST API access using a nonce—a unique number used to…
-

WordPress – Remove sensitive Rest API Endpoints
WordPress’s REST API provides a flexible way to interact with your site’s data. However, there might be instances where certain endpoints can expose sensitive information or provide vectors for potential attacks. The following PHP snippet helps tighten security by removing specific endpoints from the WordPress REST API. The Code This snippet should be placed in…
-

WordPress – Alter query on archive page
When managing a content-rich WordPress website, you might encounter a need to tweak the main query on specific pages or archives, particularly when dealing with custom post types. The PHP snippet below offers a solution to alter the post query for custom post type archives to display all posts without pagination. The Code This code…
-

WordPress – How to disable/enable plugin programmatically
Maintaining different environments for a WordPress site—such as development, staging, and production—can often require specific plugins to be active in one environment and not in others. The following PHP code snippet simplifies the process of enabling and disabling plugins based on the environment type, right from the WordPress admin dashboard. The Code The function env_plugins_notice…
-

WordPress – Login page customization
In the world of WordPress, personalizing the login page can make for a more branded and cohesive user experience. The following snippet of PHP code allows you to customize the WordPress login page by changing the logo, its link, and the title text. The Code The code snippet should be added to your theme’s functions.php…
