Ternary operators in PHP are shorthand conditional statements that allow you to write a simple if-else statement in a single line of code. The syntax for a ternary operator is: If the condition is true, the true_value is returned. Otherwise, the false_value is returned. For example, the following code: will output “less than or equal […]
Ah, PHP and string manipulations, good ol’ stuff! To turn a comma-separated string into an array in PHP, you can use the explode() function. This function splits a string by a string separator (in our case, a comma) and returns an array. Here’s a quick example: This will output: And just like that, you’ve got […]
If you want to wipe the slate clean and remove all global installs of PHPCS and WordPress standards, you can follow these steps: For PHPCS (PHP CodeSniffer): For WordPress Coding Standards: Look for a line mentioning installed_paths. Replace /path/to/wpcs with the actual path you found. These commands should remove the global installations of both PHPCS […]
Let’s get PHPCS set up for just one specific WordPress project. You can do this using Composer, which is a great way to manage dependencies on a per-project basis. This installs PHPCS in the project’s vendor directory. This should show WordPress among the available coding standards. By following these steps, PHPCS and the WordPress Coding […]
Installing PHP 8.2 on your Mac using Homebrew is pretty straightforward. As a WordPress developer, you’ll probably find this handy for your local development environment. Here’s a step-by-step guide: You should see information about PHP 8.2, indicating that the installation was successful. If you run into any issues, Homebrew’s error messages are usually pretty informative, […]
The scope resolution operator, also known as the double colon (::), is a token that allows access to static, constant, and overridden properties or methods of a class in PHP. Here’s a bit more detail on how it’s used: 1. Accessing Static Members You can use the scope resolution operator to access static methods and […]
You’ve probably come across a Canonical URL in web development, especially in the SEO world. Imagine you have the same content accessible through multiple URLs. This can confuse search engines like Google, making them unsure of which URL represents the original content. It’s kind of like having several paths to the same destination. A Canonical […]
Here’s what each part does: Remember, these are just some of the options available in a jQuery AJAX call. There are many other options and methods available, which can provide more control and flexibility over your AJAX requests. You can find more details in the jQuery AJAX documentation.
Animating a small part of an SVG with CSS involves manipulating the SVG’s properties using CSS animations. You can target specific elements or attributes within the SVG to animate them. Here’s a step-by-step guide to help you achieve this: Remember that not all SVG elements or attributes can be animated with CSS alone. More complex […]
WP-CLI is a command line interface for WordPress. You can use it to manage your WordPress sites from the command line, including plugin management. Here is the command you can use to deactivate a plugin: Replace plugin-name with the actual name of the plugin you want to deactivate. If you want to deactivate all plugins, […]
In your theme.json file in a Full Site Editor WordPress site, you can control and set up many settings for the site. You can even lock out choices for the site editor.
To output a WYSIWYG (What You See Is What You Get) field with Advanced Custom Fields (ACF) in a WordPress template, you need to add a snippet of PHP code to your template file where you want the field’s content to appear. Firstly, you’ll need to create your WYSIWYG field using ACF. In the ACF […]
You can use jQuery’s toggle() method to toggle the visibility of an element. Here is a simple example: This line of code will hide the element if it is currently visible and show it if it is currently hidden. Here’s a more complete example with a button that toggles the visibility of a div: In […]
CSS outline is a property that puts a line around the outside of an element, often used to indicate focus on the element, especially for users navigating with a keyboard instead of a mouse. For example, when a button is selected (but not yet activated), the browser might put a dotted line around the button […]
This is the radest screenshot app I’ve ever used. Totally worth the $30 bucks. You can share, annotate, grab text from images, SCROLL CAPTURE (no more need for browser-specific page capture plugins), remove icons from your desktop, GIFS, and video capture. This thing slices and dices!! https://cleanshot.com/
To escape output in PHP within WordPress, you can use the esc_html() function to convert special characters to their HTML entities. This is useful for preventing XSS (Cross-Site Scripting) attacks by ensuring that any user-provided data is properly sanitized before being outputted to the webpage
In WordPress, the recommended way to handle hard-coded strings that need to be translated is to use the __() function, which is a shorthand for the translate() function.
To run a jQuery function after the DOM has been manipulated, you can use the .ready() function or the .on() function with the DOMSubtreeModified event. Here are examples of both approaches: Using .ready(): This function will be called once the DOM has been fully loaded and is ready for manipulation. Any code you place inside […]
In WordPress, the esc_html() function is used to escape HTML entities in a string, which helps to prevent cross-site scripting (XSS) attacks. By default, this function will convert all HTML tags to their corresponding entities, including the <h1> tag. However, if you want to allow the <h1> tag in esc_html(), you can use the wp_kses() […]
You can get an array of all the blocks used in your editor by going to the inspector console and using this bit of code. In this array, you can see all the attributes for each! So, if you need to approach the editor as a whole, as in, all the blocks and not just […]
Standard WordPress blocks have a problem. If you edit the “save” parameter at all, you have to go to each post and resave it for the changes to be brought to the front end of that post. This is a deal breaker, so let’s see how to make PHP handle this for us. In our […]