How do you use a class in PHP?

How do you use a class in PHP?

Mr JoshersNov 8, 2023
Using a class in PHP involves a few steps: Here’s a full example putting all these steps together: In a modern PHP project, you would typically skip the manual require step and rely on an autoloader, but the rest of the steps remain the same.
Add a class to the post_class()

Add a class to the post_class()

Mr JoshersNov 6, 2023
In WordPress, you can definitely tack on extra classes to the post_class() function right in your template files. It’s super handy for styling your posts differently or adding some JavaScript functionality later on. You just need to pass the additional classes as an argument to the post_class() function. You can do it like this: If […]
Add ACF Value to Custom Post Type WP Admin List

Add ACF Value to Custom Post Type WP Admin List

Mr JoshersNov 1, 2023
Displaying the value of an Advanced Custom Fields (ACF) field in the WordPress admin post list can be really handy for quick overviews. You can do this by using the manage_posts_columns and manage_posts_custom_column hooks for posts or custom post types. Here’s a basic example that shows how to display an ACF field named my_things in […]
gitignore

gitignore

Mr JoshersOct 29, 2023
How do I ignore a full directory in .gitignore? Ah, ignoring a directory in .gitignore is a piece of cake! All you have to do is add the directory’s name followed by a forward slash (/) in your .gitignore file. For example, let’s say you have a directory named node_modules that you want to ignore: […]
querySelector

querySelector

Mr JoshersOct 19, 2023
querySelector is pretty versatile! It can select elements by classes, IDs, attributes, and even more complex CSS selectors. Here are some quick examples: Keep in mind that querySelector returns the first element that matches the given selector. If you want to get all elements that match a selector, you can use querySelectorAll, which returns a […]
Trigger Click after Scroll

Trigger Click after Scroll

Mr JoshersOct 19, 2023
Ah, triggering an event after scrolling a certain distance down the page is a pretty common task. You can use the window.scrollY and document.documentElement.scrollHeight properties along with the scroll event to achieve this in JavaScript. Here’s some sample code to get you started: In this example, replace #yourElementId with the actual ID of the element […]
Extend jQuery Example

Extend jQuery Example

Mr JoshersOct 13, 2023
This code extends jQuery’s :contains selector with a new case-insensitive version called :containsNC. The $.extend() method is used to add a new property to the $.expr[“:”] object, which contains all of the custom selectors that jQuery supports. The new property is an object with a single key-value pair, where the key is the name of […]
Trigger JS After An Element Has Changed. MutationObserver

Trigger JS After An Element Has Changed. MutationObserver

Mr JoshersOct 12, 2023
You can use the MutationObserver API to observe changes to the DOM and trigger a function when a specific element is added to the DOM. Here’s an example of how to use MutationObserver: In this example, we first select the node we want to observe for mutations (targetNode). We then define the options for the […]
meta_query

meta_query

Mr JoshersOct 3, 2023
The meta_query is a parameter in WordPress that is used to filter posts or custom post types based on the values of their custom fields. It is a sub-parameter of the WP_Query class and is used to specify one or more conditions that must be met by the custom fields of the posts to be […]
Vue Directives

Vue Directives

Mr JoshersOct 1, 2023
Vue provides a number of built-in directives. The exact number might depend on the version you’re using, but here’s a general list of some commonly used directives in Vue 2.x and Vue 3.x: Plus, you have the v-slot directive for named slots in Vue components, though that’s more specialized for slot content. So, there are […]
Vue Life Cycle Hooks

Vue Life Cycle Hooks

Mr JoshersOct 1, 2023
Vue’s lifecycle hooks give you a way to run custom logic at different stages of a component’s life. It’s a lot like those milestones in life—being born, going to school, getting a job, etc. Each stage presents a unique opportunity to do something meaningful. Here’s a quick rundown: beforeCreate This is like the pre-birth phase. […]
Computed Property in Vue

Computed Property in Vue

Mr JoshersOct 1, 2023
Computed properties are a super handy feature that allows you to define functions that are cached based on their dependencies and are only re-evaluated when one of those dependencies changes. So why are computed properties so great? Well, they’re perfect for performing complex calculations or transformations on data before it’s displayed in the template. For […]
Vue.js Models

Vue.js Models

Mr JoshersOct 1, 2023
In Vue.js, models are used to bind data to form inputs and update the data when the input changes. This allows for two-way data binding between the view and the model. Here’s an example of how to use a model in Vue.js: In this example, we have an input element with the v-model directive bound […]
Subgrid Lowdown

Subgrid Lowdown

Mr JoshersSep 29, 2023
here’s an example of how subgrid works: Let’s say we have a grid container with two columns and two rows: And we have a child element that we want to position within this grid: If we want to create a subgrid within this child element that inherits the same grid properties as the parent container, […]
A Quick Explanation of PHP Ternary Operators.

A Quick Explanation of PHP Ternary Operators.

Mr JoshersSep 27, 2023
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

Understanding Vue.js Components and Props: A Practical Example

Mr JoshersSep 23, 2023
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?

Why is Mac Better for Web Dev?

Mr JoshersSep 12, 2023
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

Turn a string into an array in PHP

Mr JoshersAug 31, 2023
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

Remove Global Install of PHPCS

Mr JoshersAug 25, 2023
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

PHPCS set up for just one specific WordPress project

Mr JoshersAug 25, 2023
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

Install PHP 8.2 on Mac with homebrew

Mr JoshersAug 23, 2023
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 ::

Scope Resolution Operator ::

Mr JoshersAug 21, 2023
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?

What is a Canonical URL?

Mr JoshersAug 10, 2023
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

Typical .ajax call in jQuery

Mr JoshersAug 7, 2023
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

Animate an SVG Part

Mr JoshersJul 26, 2023
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

Deactivate WordPress Plugins with WP-CLI

Mr JoshersJul 16, 2023
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

Multisite Blog URL Replacement using bash

Mr JoshersJul 15, 2023
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

Parallax Banner

Mr JoshersJun 27, 2023
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

Get Post Thumbnail By Post ID

Mr JoshersJun 21, 2023
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

Disable Most Typography & Color Choices in WordPress

Mr JoshersJun 14, 2023
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

Output a WYSIWYG Field with ACF

Mr JoshersJun 2, 2023
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()

Now I See You, Now I toggle()

Mr JoshersMay 31, 2023
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?

Hide the Outline?

Mr JoshersMay 31, 2023
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

Cleanshot X

Mr JoshersMay 28, 2023
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/
Simple CSS Loading Animation

Simple CSS Loading Animation

Mr JoshersMay 5, 2023
Quick and dirty but nice looking pure CSS loading animation.
A kid escaping out a window with the WordPress logo painted on the wall. Photo by Avi Waxman on Unsplash

All output should be run through an escaping function in WordPress

Mr JoshersApr 30, 2023
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
We Like You Too. Photo by Adam Jang on Unsplash.

Translation Function for Hard-Coded String in WordPress

Mr JoshersApr 29, 2023
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

Remove Text in a String with PHP

Mr JoshersApr 29, 2023
You can remove any text, like asterisks (*), for example, from a string using the str_replace() function
Run jQuery after DOM Manipulation

Run jQuery after DOM Manipulation

Mr JoshersApr 27, 2023
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 […]
A kid escaping out a window with the WordPress logo painted on the wall. Photo by Avi Waxman on Unsplash

Allow HTML Tags while using an escaping function in WordPress

Mr JoshersApr 27, 2023
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() […]
WordPress Blocks

Setup a Block as a Plugin

Mr JoshersApr 15, 2023
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 …

Spread Operator …

Mr JoshersApr 8, 2023
In JavaScript, the … syntax is called the “spread operator.” It is also difficult to Google!
WordPress Blocks

List All Blocks in the Console

Mr JoshersApr 6, 2023
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 […]
WordPress Blocks

Blocks That You Don’t Need to Resave When You Edit Them

Mr JoshersApr 3, 2023
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

Write HTML in PHP with ob_start

Mr JoshersApr 2, 2023
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

Get Query Parameter PHP

Mr JoshersMar 6, 2023
It’s pretty easy to simply grab a URL Query Parameter, but here’s how to do it safely.
Change a Key Name PHP

Change a Key Name PHP

Mr JoshersMar 6, 2023
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

Complex Arrays PHP

Mr JoshersMar 6, 2023
Arrays can get complicated pretty quickly. Here’s a quick lowdown on how they are made, and how they are accessed.
Pretty Print Array in PHP

Pretty Print Array in PHP

Mr JoshersMar 6, 2023
Just a quick snippet for printing out an array in a nice way.
Ternary Operator

Ternary Operator

Mr JoshersMar 5, 2023
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

Find that element that goes off page

Mr JoshersMar 5, 2023
If an element on the page is wider than the document, it’ll get logged to the console.
Javascript OOP

Javascript OOP

Mr JoshersMar 5, 2023
Javascript Object Oriented Programming basic setup. And I’m using jQuery because, why not? It’s already in WordPress, anyway.
Register Rest Field

Register Rest Field

Mr JoshersMar 5, 2023
This will put anything you want into the wp api call for a post, page, or any custom post type.
WP Custom Route API

WP Custom Route API

Mr JoshersMar 5, 2023
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

Hipster Ipsum

Mr JoshersFeb 19, 2023
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.
Bob Ross Painting

Bob Ross

Mr JoshersFeb 19, 2023
Just some happy ipsum can live right over here bobrosslipsum.com. Just go back and put one little more happy tree in there.