A Quick Explanation of PHP Ternary Operators.
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 […]
Understanding Vue.js Components and Props: A Practical Example
In the world of web development, Vue.js has rapidly gained popularity as a progressive JavaScript framework for building interactive and dynamic user interfaces. With its simplicity and versatility, Vue.js has become a developer favorite. To illustrate how Vue.js works and how components and props function, let’s dissect a simple Vue.js code snippet. Example Code In […]
Why is Mac Better for Web Dev?
An objective case for why some web and WordPress developers prefer using Macintosh (Mac) computers for their work
Turn a string into an array in PHP
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 […]
Remove Global Install of PHPCS
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 […]
PHPCS set up for just one specific WordPress project
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 […]
Install PHP 8.2 on Mac with homebrew
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, […]
Scope Resolution Operator ::
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 […]
What is a Canonical URL?
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 […]
Typical .ajax call in jQuery
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.
Animate an SVG Part
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 […]
Deactivate WordPress Plugins with WP-CLI
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, […]
Multisite Blog URL Replacement using bash
If you have a multisite with lots and lots of blogs, updating the URL’s for each wp_{id}_options table can be difficult if you need to do it manually. Here’s how to use a bash script so you don’t bash in your head doing it table by table.
Parallax Banner
Creating a parallax effect for a banner can be achieved using CSS and JavaScript. The basic idea of the parallax effect is that the background content (e.g., an image) and the foreground content (e.g., text) move at different speeds when the user scrolls, giving the illusion of depth.
Get Post Thumbnail By Post ID
You can use the has_post_thumbnail function to retrieve the post thumbnail by post ID in WordPress.
Disable Most Typography & Color Choices in WordPress
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.
Output a WYSIWYG Field with ACF
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 […]
Now I See You, Now I toggle()
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 […]
Hide the Outline?
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 […]
Cleanshot X
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/
All output should be run through an escaping function in WordPress
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
Translation Function for Hard-Coded String in WordPress
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.
Remove Text in a String with PHP
You can remove any text, like asterisks (*), for example, from a string using the str_replace() function
Run jQuery after DOM Manipulation
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 […]
Allow HTML Tags while using an escaping function in WordPress
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() […]
Setup a Block as a Plugin
WordPress made a rad package that sets up webpack, Babel, and all the other packages we need to run React for WordPress Blocks.
Spread Operator …
In JavaScript, the … syntax is called the “spread operator.” It is also difficult to Google!
List All Blocks in the Console
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 […]
Blocks That You Don’t Need to Resave When You Edit Them
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 […]
Write HTML in PHP with ob_start
The “OB” stands for “output buffer”, and essentially anything that comes after the “ob_start” and before the “ob_get_clean” is what’s returned in the function.
Get Query Parameter PHP
It’s pretty easy to simply grab a URL Query Parameter, but here’s how to do it safely.
Change a Key Name PHP
I guess it’s pretty simple, but it’s nice to have a reminder in case things aren’t going well. Sanity check. 🙂
Complex Arrays PHP
Arrays can get complicated pretty quickly. Here’s a quick lowdown on how they are made, and how they are accessed.
Ternary Operator
Inline if this then that else this other thing. Handy when you need to do this sort of thing in a template literal.
Find that element that goes off page
If an element on the page is wider than the document, it’ll get logged to the console.
Javascript OOP
Javascript Object Oriented Programming basic setup. And I’m using jQuery because, why not? It’s already in WordPress, anyway.
Register Rest Field
This will put anything you want into the wp api call for a post, page, or any custom post type.
WP Custom Route API
You can do a lot with the WordPress API, but it gets really good when you can make your own WP API endpoints.
Hipster Ipsum
When it comes to testing and Ipsum, Hipsters are the best. hipsum.co
If you need an image or two, picsum.photos has some great options built right in.