Hi everyone, I’m GreenAffiliates

Hello, we are Green Affiliates, world marketing leader in the cannabis industry. We are located in Vancouver, BC, and we partner with some of the most influential Northern American brands. Our platform enables influencers and merchants to form a beneficial relationship with product revenue for both.

10 Popular APIs for Addresses

Getting accurate, validated address data is crucial for businesses and organizations that reach out to customers for shipping, marketing purposes, property , social programs and other reasons. In addition to correct house number, street name, city, zip or postal code, address data can also be geolocation data, such as latitude/longitude. The best way for developers to get correct address data for their applications is to use a suitable Addresses API.

Build Notification Banners With ElmaStudio’s Latest Block Plugin

A friend and I were discussing the need for more one-off block plugins earlier today. He had mentioned that WordPress has this powerful block search feature that rarely turns up anything useful. Most are part of collections that do not appear in the results. This was part of a more wide-ranging conversation that I am sure I will tackle on another day.

However, it reminded me that I had a couple of ElmaStudio’s block plugins sitting in the backlog along with some notes on them. The team released Aino Accordion FAQ Block and Aino Notification Banner Block three weeks ago. The latter piqued my interest more so than the former.

Adding an error notification via the Aino Notification Banner plugin in the WordPress editor.
Inserting an error notification.

The two-person team of Ellen Bauer and Manuel Esposito could have continued amassing a collection within their existing Aino Blocks plugin. Instead, they took a turn down the path few have traveled. They are now releasing single-purpose blocks.

“We plan to work on smaller add-on single blocks from now on as well,” said Bauer in the comments on my last review of their theme and block library. “Blocks that are needed for building more complex block page templates.”

Notification boxes are so commonplace that you almost wonder why they are not a part of core WordPress. Many block collection plugins bundle one or multiple, but it is hard to find a solid solution as a single block.

The block has six statuses that users can select from:

  • Welcome
  • Info
  • Help
  • Success
  • Warning
  • Error

Each status has its own icon and default colors. The colors are customizable, but the icon itself is not. I am a fan of the decision because it means one less choice I must make. There is also an option to hide the icon and switch between fill and outline versions.

Displaying multiple notification box styles from the Aino Notification Banner plugin: welcome, info, help, info, and warning.
Testing different notification statuses.

The block also displays a “dismiss” button for visitors to close the banner on the front end. The state is not saved, so if the visitor returns to the page, it will reappear. I would like to see an option to store the banner state in the browser in the future.

I like the plugin for its simplicity. The default output works well enough for most themes, but it has enough options for users to customize it.

The upcoming site editor is where the plugin could really shine. Of course, a user would need a block theme to use it there, such as ElmaStudio’s Aino. The block offers a quick and easy way of plopping something like a sales banner across the top of the site.

Using the Aino Notification Banner plugin to insert a sales notice at the top of the site via WordPress's site editor.
Adding a sales banner at the top of the site.

I do have a few nit-picks, of course. These are not OMGBBQ problems that make the plugin unusable. Instead, they are places where it could be improved.

Because many themes use a top margin approach to vertical rhythm, it can disrupt the alignment of the icon and paragraph. The plugin should zero this out.

If anyone else runs into this issue, the following CSS is a quick fix:

.wp-block-ainoblocks-notification-block .content-wrapper p:first-of-type {
    margin-top: 0;
}

One of the downsides to the plugin is its custom system for borders and padding. From a development perspective, I prefer the plugin’s system under the hood, which uses a curated set of values that keep a user from doing something really crazy. It offers a balance between flexibility and rational choices.

Showcasing the custom border and padding controls from the Aino Notification Banner plugin, which deviates from the WordPress standard.
The plugin’s custom controls.

I have argued that most design controls should have such a system — the same one that is in place for font sizes and colors — ad nauseum. However, Gutenberg and core have moved in a different direction, preferring arbitrary user-defined values over a range of presets. Plugin authors should fall in line for the sake of users.

As a user, I prefer consistency. I want the interface to be the same, regardless of whether I am dealing with a core or third-party block. Having to learn multiple methods to add padding or change a border creates unnecessary friction.

The plugin’s custom system also conflicts with default block styles that theme authors can define in their theme.json files. The standards set by WordPress create a bridge between plugins and themes that the platform has never had before. The more block developers follow it, the easier it is for theme designers to work within the system.

There are other options. In the past week, the Alert Box Block plugin landed in the directory. It provides far more icon options and more design controls in general. However, its UI is so different from the WordPress standard that I cannot imagine using it.

When I talk about issues with Aino Notification Banner, it must be taken into context. I point out problems because I see its potential. I want the developers to continue iterating on it, improving what is already one of the best options out there. This is something that ElmaStudio has proven it can do with earlier projects, so I look forward to what the plugin looks like in the future. For now, it is a solid option for users who need to display notification boxes.

How to Start a Media Business

It used to be that a handful of media companies with deep pockets owned and controlled the industry.

These conglomerates had complete control of the information and entertainment we consumed. 

The digital age has completely overturned the industry. 

Now, anyone with a computer and camera and an exciting take on news or entertainment can create a media company. 

If you’ve always been interested in the media business, there has perhaps never been a better time to join the fray. 

The Easy Parts of Starting a Media Business

Not everything about starting a media business has to be complicated.

One of the most promising prospects of getting into this business is the flexibility it offers. You are free to dedicate as little or as much time to starting and growing your business. In addition, you can start as a solopreneur handling all aspects of your business. This way, you can keep your day job until your company is profitable enough to justify running it full-time.

A media business also has low barriers to entry. Specifically, a digital media business requires little more than your time and effort. You can get started even without an office space, working out of your home. You can also get started with just the basics, like a workstation, internet connection, and website.

Similarly, there are few overhead costs when running a media business, especially in the beginning. You don’t need to worry about paying employees, inventory, storefront, and other overheads associated with most types of business. The media business also has potentially high gross margins. Coupled with the low overhead costs, you get to keep much of your profit.

Planning your media business is also more straightforward than it seems. A tool like Bionic has everything you need for media planning. You can easily create media plans, build flowcharts, predict KPIs, and automate your request for proposal (RPF) process. This software helps increase your productivity, allowing you to spend more time focusing on critical factors like building your client pipeline. 

Finally, all the information you need to start and run a successful media company is freely available. There are bountiful blogs, websites, Facebook groups, eBooks, YouTube videos, and other media dedicated to helping you start your business. Much of this information is also high value and completely free. You also don’t necessarily need specific media education or certification to get started.

The Hard Parts of Starting a Media Business

There are many attractive reasons to get into the media business. But not everything is rosy in this line of work. Like starting any other business, you can expect challenges and drawbacks when creating your media company.

The most immediate challenge you’ll face when starting your business is competition. The media business is crowded, and some of your competitors have been in the industry for decades. Building trust with your audience and clients can prove challenging. It will take some time before you can carve out a space for yourself in the media landscape.

Another challenge once you’re up and running is cash flow. This is especially true in the weeks and months following your big company launch. Starting your business means you are self-employed. There are no benefits or paid time off. Additionally, you don’t have a consistent check to look forward to. You only get paid for your work, and you can expect some dry months in the beginning.

Starting a media business is also labor-intensive. You’ll likely be handling all the administrative tasks on top of making major business decisions. In addition, your business could easily obliterate your social life and even get in the way of spending quality time with your loved ones.

Lastly, maintaining a positive brand image can prove challenging. You are putting yourself out there as an expert makes you an open target for criticism. Navigating the political and social landscape can be tricky. And, the internet can be brutal for people who are actively putting out their ideas and opinions. You need thick skin to succeed in this business.

However, a media business can be rewarding despite the challenges. The media market is incredibly fragmented in the digital age. There’s a good chance for you to find a niche that you are passionate about, matches your expertise, and where you are likely to succeed.

If you’re ready to pull the trigger on your business idea, here’s how to create a media business step by step.

Step 1 – Create a Plan for Your Business

The media business is an extensive industry. According to Law Insider, you’re in the media business if you engage in creating, producing, distributing, exhibiting, or otherwise exploiting visual, audio, or audio-visual works or recordings. Specific works falling under this definition include television, books, radio broadcasting, periodical publishing, and merchandising.

So, it is necessary to narrow down your idea of the media business you want to create.

Choose Your Niche

There are almost infinite options when starting a media business. So, choose a niche to get started building your business. Some of the most common media niches include:

  • Publishing – including newspapers, magazines, books, blogs, research papers, references, and comics.
  • Video & Animation – including video products such as YouTube, broadcast television, and animation
  • Video Games – including all types of virtual environments like virtual reality
  • Film – may include producing and distributing documentaries, movies, and music videos
  • Streaming Media – refers to on-demand media that people can access online
  • Audio – such as broadcast radio or podcasts
  • Music – includes producing, distributing, and performing music
  • Interactive Media – like apps, websites, and software

The business niche you choose is entirely up to you. But, there are a few guidelines that can help you choose the best niche. For example, you want to start with a general area where you are knowledgeable. To this end, think about your passions, hobbies, and previous work experience.

Then, identify a gap within that market where you position yourself to solve problems. For example, Michael Arrington started the now popular website TechCrunch.com as a part-time blogger. He focused solely on technology news, allowing him to position his blog as the go-to source for technology news. As a result, TechCrunch was acquired by AOL in September 2010 for approximately 40 million.

Create a Business Plan

A business plan will inform almost every aspect of building and running your business. So, it is worth dedicating some time and effort to creating a plan for your business. Primarily, the business plan will help you identify your goals and objectives. It will also chart a path to reaching the objectives and help you manage your budget and time.  

Some of the sections to detail in your business plan include:

  • Executive summary
  • Financial considerations
  • Objectives
  • Mission
  • Keys to success

The Small Business Administration (SBA) website offers extensive resources to help you plan, launch, manage, and grow your business.

Step 2 – Sign Up for Media Planning Software

Media planning can be tricky, especially when getting into business for the first time. Media planning software like Bionic helps to make the process easier. The Bionic team will even set up your account within an hour of requesting a free trial. The platform even sets up training at no extra cost to ensure you get the most out of the software suite.

Request a Free Trial

Simply visit this link to request your free trial. You’ll need to provide a few details including your first and last name, phone number, and email. Then, you’ll receive an email from the customer support team with the credentials for your active account.

The free trial includes all of the software’s features. The team will also help you create your first media plan. This software has everything you need to look professional from the get-go. Bionic works for all media channels, including radio, digital, TV, and print.

The software costs $195 per user per month. You also get a 14-day money-back guarantee in case you don’t like what the tool has to offer.

Step 3 – Identify Your Target Audience

It is also crucial that you identify the customer group you want to target with your media company. This step will also help you determine the direction of your business. For example, your target audience will determine the type of content you create, the most effective marketing channels, and even how you monetize your media business.

Learn the Types of Target Audiences

Breaking up target audiences into segments makes it easier to find your ideal audience. Some of the categories of target audiences include:

Interest – this group includes audiences with specific hobbies, interests, and entertainment preferences. Interest groups are especially valuable for creating brand loyalty. Therefore, it is worth segmenting audiences into different groups under this category. For example, you can have different groups for entertainment preferences, hobbies, and interests.

Purchase Intention – Audiences in this group are the spenders. They will be the backbone of how your media company generates revenue.

Subcultures – This group is even more effective for creating a community around your brand. Audiences in this group share everyday experiences such as entertainment fandoms or music genres. You can go a long way in creating a loyal following if you understand what motivates this target group.

Ask the Right Questions

There are a few critical questions that can help you identify your ideal target market.

  • The type of media you plan to offer your customers
  • The market segment that benefits most from your media
  • What is unique about the content you plan to offer?

The answers to these questions should easily guide you in identifying an ideal target audience. This way, you can create relevant media that appeals to your customer base. Then, you’ll be able to communicate your value through your core messages and media services.

Then, segment your target audience according to age group, interests, location, and language. This step will further help you target your message to the correct audiences.

Define Your Value Proposition

Defining your value proposition helps to set the pace for your business. Media businesses are a dime a dozen. So, it helps if you can figure out the unique value you have to offer. Does your media company offer unbiased news? Do you have a fresh perspective on entertainment news? 

Think about what you have to offer that is fresh, unique, and valuable in the marketplace. You’ll face a lot of competition from more established media companies. Having a unique value proposition will make it easier to take some much-needed market share.

Step 4 – Register Your Business

You’ll need to set up a business structure before you can get to the hands-on parts of starting a media business. Registering your business will help you appear professional right out of the gate. Also, registering your business has practical implications like paying taxes, liability protections, opening a business account, and hiring employees.

Choose a Business Structure

For most people, a Limited Liability Company (LLC) is the best business structure for a media company. An LLC is flexible, allowing you to publish alone or bring on partners. You also get limited liability protection, meaning that you are not personally liable for your business’ losses, debts, lawsuits, and other liabilities. This way, you can protect your personal finances and assets.

Additionally, an LLC offers flexible tax options to benefit your bottom line. For example, you can choose to be taxed as a partnership or corporation. We have a great guide here to help you choose the best business structure for your operation. At the very least, you should look into limited liability protection. So, a sole proprietorship or partnership is out of the question. These business structures do not offer limited liability protection. Your personal assets and finances will be fair game if you run into business difficulties like debt or lawsuits.  

Register Your Business

Once you’ve settled on a business structure, it’s time to make it official. The process of registering an LLC is relatively straightforward. You’ll need to:

  • Choose a name for your LLC
  • File an Articles of Organization with the secretary of state
  • Pay your state filing fee
  • Create an operating agreement
  • Obtain an Employer Identification Number (EIN) from the IRS

I recommend using a business formation service or a legal service. Of course, you can always register the LLC on your own. But, you may run into challenges in any of the steps. A formation service takes responsibility for the entire process. This option helps you form your LLC quickly and easily.

Step 5 – Start Creating Content

This step may look a little different depending on the medium you choose. For example, creating an entertainment news blog will look a lot different than a podcast. But, there are commonalities regardless of the media platform you choose to reach your audience.

Plan Your Content

Content planning is the foundation of the content creation process. So, it is worth taking this step seriously. First, start by researching topics for your content. This shouldn’t be too difficult if you’ve already picked a niche and identified your audience.

Still, you may be overwhelmed with content ideas and topics within your niche.

To solve this problem, research keywords that can help drive traffic to your platform. Google AdWords is an excellent tool for this purpose. It comes with a Keyword Planner. Here, you can get valuable search volume data for your targeted keywords. This tool is entirely free, and you can easily download reports.

You’ll want to make sure that you don’t have direct competition from major players. For example, it will take a lot to compete against The Economist if you plan to offer similar content.

Choose a Topic You Like

This point is especially relevant if you’ll be creating your own content. Building valuable content is a long-term game. So, you may not be motivated enough to produce content consistently if you do not enjoy the topic. On the other hand, search engines and audiences alike reward consistency.

For text-based content, make sure that your posts are easy to read. Images, headers, and bullet points help to make your content more scannable. Again, it may sound obvious but stick to the topic best you can.

For video-based content, be sure to create a structure. A good video should include a hook, a summary of the video, the problem you’re hoping to solve, and your unique take on solving the problem. Finally, end the video with a call to action.

Again, the key to a successful media company is consistency. So, make a schedule for creating content and stick to it. The Bionics software will prove invaluable for this step. 

Step 6 – Choose How You’ll Make Money

The main reason many people get into the media business is to make money. Fortunately, there are various avenues for generating profits in this business. You can also combine two or more business models to increase your revenue. Here’s a look at your monetization options for a media business:

Affiliate Linking

Traditionally, affiliate linking has been associated with social media influencers. But, even mainstream media companies are taking advantage of this potentially lucrative revenue source. For example, the New York Times runs a review website known as Wirecutter.

It is essential to include a disclaimer about your affiliate relationships. Similarly, ensure that the affiliate links are clearly marked. This step will help you maintain your journalistic integrity.

Sponsored Content

Sponsored is a relatively new revenue source. But, many digital media companies leverage sponsored content. Here, companies pay to advertise their content on your platform, alongside yours. You can create the sponsored content or have businesses submit it.

Either way, make sure that the sponsored content is clearly marked. Again, it helps your integrity if your audience doesn’t confuse your regular content with sponsored content.

Memberships and Subscriptions

Here, you put your content behind a paywall. Your audience needs to subscribe to get access to the content. This monetization method is very similar to how traditional media makes money.

Subscriptions and memberships can be tricky to monetize. But, it is still possible if you have a sizeable and loyal membership. You’ll need to offer a lot of value to convince your audience to subscribe to your content.

Display Advertising

Most media companies make money from display advertising. You can offer space on your website for businesses to advertise their products or services.

Display advertising is versatile, effective, and relatively easy to do. So, it is worth a shot when considering how to monetize your media business. This option is particularly profitable when you get a large audience. 

Gutenberg Contributors Propose Renaming Reusable Blocks

WordPress’ Reusable blocks may soon be getting re-named, as the feature’s distinct capabilities are less recognizable from its name following the introduction of patterns.

When the Gutenberg project first took off, nobody had any idea how important patterns would become in the page building experience, or that they would be getting their own directory on WordPress.org. During a demo at WordCamp Europe 2021, Gutenberg lead architect Matías Ventura commented on how transformative patterns have been for making page design approachable for users.

“Perhaps it was a smaller part of the roadmap initially but it’s becoming a centerpiece – especially because it allows…world class designers to provide a starting point for users and users get to learn design as they are interacting with themes,” Ventura said. 

A year later, patterns have made their way to the forefront of theme design and development with an excitement that rivals the introduction of widgets in WordPress’ earlier days. WordPress 5.9 will feature pattern insertion directly from the Pattern Directory so users will be able to change their patterns as often as they like, without having to switch themes. Coming in Gutenberg 11.8, the pattern inserter will highlight featured patterns from the directory in the initial view, instead of displaying the first alphabetical category. Contributors are also considering a path for allowing themes to surface specific patterns from the directory instead of bundling them.

In light of all this activity around Patterns, Reusable blocks are in need of a renaming that is more descriptive.

 “In the end, patterns are also reusable pieces of design,” Ventura said.

“Given the nature of these [Reusable] blocks is to have content in sync wherever it’s displayed — edit once; update everywhere — I propose we change the name in the UI to ‘Synced Blocks’ and adjust the block description a little bit to clarify that.”

The UI for Reusable Blocks is confusing because it is built on top of assumptions that users know the intricacies of how they work. WordPress developer Lee Hodson summarized the problem and how the current UI leads to reusable blocks being accidentally edited:

The save reusable blocks dialog is nice but how many creators actually understand what this save dialog means? On the surface it looks as though everyone should understand the save/not save option but it’s meaning is only obvious when you understand that reusable blocks are (currently) meant to either (a) not be edited or (b) edits to them are meant to affect all instances of the same block and (c) that reusable blocks can be converted to editable blocks (and not everyone immediately understands the difference) when edits to reusable blocks are meant to be independent of the block’s template.

I feel that a nice idea (reusable blocks) has been very badly implemented and many creators are blissfully unaware of its pitfalls until they realize their ‘template blocks’ have been overwritten.

Several contributors participating in the renaming discussion concurred that “Synced Blocks” would be a better name for the feature. This suggestion is the frontrunner so far. The conversation is still open and consideration of this proposal has been added to the Reusable Blocks Improvements tracking issue.

How to Find the Right Collaborative Coding Tool for Remote Pair Programming

Remote development is clearly here to stay, and when you need to collaborate with your team, starting a Zoom meeting or Hangout (er … Google meeting) is probably something you think of doing first. However, several developer-focused solutions that are much better suited for remote development are available today — but how do you know which one to pick? This guide will help you make that decision.

As you read this guide, you might wonder how I know an awful lot about these solutions. The fact is, I work for Genuitec, which makes CodeTogether. What you see below is the result of our continuing study of this landscape to see how we stack up against our competitors and to decide what we need to focus on next. This guide aims to be factual, and in an effort to remain unbiased, I do not delve too deeply into the quality or capabilities of each feature.

Help naming company

Help please,

I'm trying to decide between names for my company:
Office Surgery
or
Office Surgery Centers

I am starting a company to help doctors open a surgery suite in their office. I own the domain: www.officesurgery.com and have email addresses with @officesurgery.com including info@officesurgery.com

Any suggestions? I am hoping to get people to vote on which they prefer given my domain ownership, etc.

THANK YOU!!!

User-Friendly Newsletters with AcyMailing for WordPress

User-Friendly Newsletters with AcyMailing for WordPressIf you don’t have a newsletter set up already, now is the time to get started. A newsletter has limitless uses; you could inform users about your latest articles, thank them for signing up, remind them about abandoned carts, or invite them to upcoming events. And all of this can be totally automated, sending emails […]

The post User-Friendly Newsletters with AcyMailing for WordPress appeared first on WPExplorer.

Easy Access to OAuth 2.0 Protected Resources With the Spring WebClient

Spring Framework 5.0 introduced Spring WebClient as part of the WebFlux reactive web stack. WebClient is a reactive HTTP client that provides a functional and fluent API based on Reactor, allowing declarative composition of asynchronous non-blocking requests.  No need to  manage concurrency issues. Support for filter registration means it can intercept and modify requests, which can be used for cross-cutting concerns such as authentication, as demonstrated in this tutorial.

The WebTestClient is also an HTTP client designed for application testing. With a testing interface wrapper to check replies, WebClient can be used to execute end-to-end HTTP testing and connect to a live server. It can also bind to a controller or application context and simulate requests and responses without requiring a running server.

REST Services With Apache Camel

Microservices are becoming a very popular architectural style for developing greenfield applications and also for brownfield solutions. People are moving away from the monolith solutions due to added advantages like faster development and go-to-market, increased adoption of containerization and small teams, and a lighter codebase. 

You can use either Spring Boot, Quarkus, or Lagom frameworks to develop the REST services. I would like to show how we can use Apache Camel, a leading opensource integration framework, to write REST services easier and quicker using the REST domain-specific language (DSL).

How to Build a Nearly Headless WordPress Website

I believe that a traditional WordPress theme should be able to work as effectively as a static site or a headless web app. The overwhelming majority of WordPress websites are built with a good ol’ fashioned WordPress theme. Most of them even have good caching layers, and dependency optimizations that make these sites run reasonably fast. But as developers, we have accomplished ways to create better results for our websites. Using a headless WordPress has allowed many sites to have faster load speeds, better user interactions, and seamless transitions between pages.

The problem? Maintenance. Let me show you another possibility!

Let’s start by defining what I mean by “Traditional” WordPress, “Headless” WordPress, and then “Nearly Headless” WordPress.

Traditional WordPress websites

Traditionally, a WordPress website is built using PHP to render the HTML markup that is rendered on the page. Each time a link is clicked, the browser sends another request to the server, and PHP renders the HTML markup for the site that was clicked.

This is the method that most sites use. It’s the easiest to maintain, has the least complexity in the tech, and with the right server-side caching tools it can perform fairly well. The issue is, since it is a traditional website, it feels like a traditional website. Transitions, effects, and other stylish, modern features tend to be more difficult to build and maintain in this type of site.

Pros:

  1. The site is easy to maintain.
  2. The tech is relatively simple.
  3. There is great compatibility with WordPress plugins.

Cons:

  1. Your site may feel a little dated as society expects app-like experiences in the browser.
  2. JavaScript tends to be a little harder to write and maintain since the site isn’t using a JavaScript framework to control the site’s behavior.
  3. Traditional websites tend to run slower than headless and nearly headless options.

Headless WordPress websites

A headless WordPress website uses modern JavaScript and some kind of server-side RESTful service, such as the WordPress REST API or GraphQL. Instead of building, and rendering the HTML in PHP, the server sends minimal HTML and a big ol’ JavaScript file that can handle rendering any page on the site. This method loads pages much faster, and opens up the opportunity to create really cool transitions between pages, and other interesting things.

No matter how you spin it, most headless WordPress websites require a developer on-hand to make any significant change to the website. Want to install a forms plugin? Sorry, you probably need a developer to set that up. Want to install a new SEO plugin? Nope, going to need a developer to change the app. Wanna use that fancy block? Too bad — you’re going to need a developer first.

Pros:

  1. The website itself will feel modern, and fast.
  2. It’s easy to integrate with other RESTful services outside of WordPress.
  3. The entire site is built in JavaScript, which makes it easier to build complex websites.

Cons:

  1. You must re-invent a lot of things that WordPress plugins do out of the box for you.
  2. This set up is difficult to maintain.
  3. Compared to other options, hosting is complex and can get expensive.

See “WordPress and Jamstack” for a deeper comparison of the differences between WordPress and static hosting.

I love the result that headless WordPress can create. I don’t like the maintenance. What I want is a web app that allows me to have fast load speeds, transitions between pages, and an overall app-like feel to my site. But I also want to be able to freely use the plugin ecosystem that made WordPress so popular in the first place. What I want is something headless-ish. Nearly headless.

I couldn’t find anything that fit this description, so I built one. Since then, I have built a handful of sites that use this approach, and have built the JavaScript libraries necessary to make it easier for others to create their own nearly headless WordPress theme.

Introducing Nearly Headless WordPress

Nearly headless is a web development approach to WordPress that gives you many of the app-like benefits that come with a headless approach, as well as the ease of development that comes with using a traditional WordPress theme. It accomplishes this with a small JavaScript app that will handle the routing and render your site much like a headless app, but has a fallback to load the exact same page with a normal WordPress request instead. You can choose which pages load using the fallback method, and can inject logic into either the JavaScript or the PHP to determine if the page should be loaded like this.

You can see this in action on the demo site I built to show off just what this approach can do.

For example, one of the sites implementing this method uses a learning management system called LifterLMS to sell WordPress courses online. This plugin has built-in e-commerce capabilities, and sets up the interface needed to host and place course content behind a paywall. This site uses a lot of LifterLMS’s built-in functionality to work — and a big part of that is the checkout cart. Instead of re-building this entire page to work inside my app, I simply set it to load using the fallback method. Because of this, this page works like any old WordPress theme, and works exactly as intended as a result — all without me re-building anything.

Pros:

  1. This is easy to maintain, when set-up.
  2. The hosting is as easy as a typical WordPress theme.
  3. The website feels just as modern and fast as a headless website.

Cons:

  1. You always have to think about two different methods to render your website.
  2. There are limited choices for JavaScript libraries that are effective with this method.
  3. This app is tied very closely to WordPress, so using third party REST APIs is more-difficult than headless.

How it works

For something to be nearly headless, it needs to be able to do several things, including:

  1. load a page using a WordPress request,
  2. load a page using JavaScript,
  3. allow pages to be identical, regardless of how they’re rendered,
  4. provide a way to know when to load a page using JavaScript, or PHP, and
  5. Ensure 100% parity on all routed pages, regardless of if it’s rendered with JavaScript or PHP.

This allows the site to make use of progressive enhancement. Since the page can be viewed with, or without JavaScript, you can use whichever version makes the most sense based on the request that was made. Have a trusted bot crawling your site? Send them the non-JavaScript version to ensure compatibility. Have a checkout page that isn’t working as-expected? Force it to load without the app for now, and maybe fix it later.

To accomplish each of these items, I released an open-source library called Nicholas, which includes a pre-made boilerplate.

Keeping it DRY

The biggest concern I wanted to overcome when building a nearly-headless app is keeping parity between how the page renders in PHP and JavaScript. I did not want to have to build and maintain my markup in two different places — I wanted a single source for as much of the markup as possible. This instantly limited which JavaScript libraries I could realistically use (sorry React!). With some research, and a lot of experimentation, I ended up using AlpineJS. This library kept my code reasonably DRY. There’s parts that absolutely have to be re-written for each one (loops, for example), but most of the significant chunks of markup can be re-used.

A single post template rendered with PHP might look like something like this:

<?php
if ( have_posts() ) {
  while ( have_posts() ) {
    the_post();
    if ( is_singular() ) {
      echo nicholas()->templates()->get_template( 'index', 'post', [
        'content' => Nicholas::get_buffer( 'the_content' ),
        'title'   => Nicholas::get_buffer( 'the_title' ),
      ] );
    }
  }
}
?>

That same post template rendered in JavaScript, using Alpine:

<template x-for="(post, index) in $store.posts" :key="index">
  <?= nicholas()->templates()->get_template( 'index', 'post' ) ?>
</template>

Both of them use the same PHP template, so all of the code inside the actual loop is DRY:

$title   = $template->get_param( 'title', '' );

// Get the title that was passed into this template, fallback to empty string.
$content = $template->get_param( 'content', '' ); // Get the cotent passed into this template, fallback to empty string.

?>
<article x-data="theme.Post(index)">
  <!-- This will use the alpine directive to render the title, or if it's in compatibility mode PHP will fill in the title directly -->
  <h1 x-html="title"><?= $title ?></h1>
  <!-- This will use the Alpine directive to render the post content, or if it's in compatibility mode, PHP will fill in the content directly -->
  <div class="content" x-html="content"><?= $content ?></div>
</article>

Related: This Alpine.js approach is similar in spirit to the Vue.js approach covered in “How to Build Vue Components in a WordPress Theme” by Jonathan Land.

Detect when a page should run in compatibility mode

“Compatibility mode” allows you to force any request to load without the JavaScript that runs the headless version of the site. When a page is set to load using compatibility mode, the page will be loaded using nothing but PHP, and the app script never gets enqueued. This allows “problem pages” that don’t work as-expected with the app to run without needing to re-write anything.

There are several different ways you can force a page to run in compatibility mode — some require code, and some don’t. Nicholas adds a toggle to any post type that makes it possible to force a post to load in compatibility mode.

Along with this, you can manually add any URL to force it to load in compatibility mode inside the Nicholas settings.

These are a great start, but I’ve found that I can usually detect when a page needs to load in compatibility mode automatically based on what blocks are stored in a post. For example, let’s say you have Ninja Forms installed on your site, and you want to use the validation JavaScript they provide instead of re-making your own. In this case, you would have to force compatibility mode on any page that has a Ninja Form on it. You could manually go through and add each URL as you need them, or you can use a query to get all of the content that has a Ninja Forms block on the page. Something like this:

add_filter( 'nicholas/compatibility_mode_urls', function ( $urls ) {
  // Filter Ninja Forms Blocks
  $filtered_urls = Nicholas::get_urls_for_query( [
    'post_type' => 'any',
    's' => 'wp:ninja-forms/form', // Find Ninja Forms Blocks
  ] );

  return array_merge( $urls, $filtered_urls );
} );

That automatically adds any page with a Ninja Forms block to the list of URLs that will load using compatibility mode. This is just using WP_Query arguments, so you could pass anything you want here to determine what content should be added to the list.

Extending the app

Under the hood, Nicholas uses a lightweight router that can be extended using a middleware pattern much like how an Express app handles middleware. When a clicked page is routed, the system runs through each middleware item, and eventually routes the page. By default, the router does nothing; however, it comes with several pre-made middleware pieces that allows you to assemble the router however you see-fit.

A basic example would look something like this:

// Import WordPress-specific middleware
import {
  updateAdminBar,
  validateAdminPage,
  validateCompatibilityMode
} from 'nicholas-wp/middlewares'

// Import generic middleware
import {
  addRouteActions,
  handleClickMiddleware,
  setupRouter,
  validateMiddleware
} from "nicholas-router";

// Do these actions, in this order, when a page is routed.
addRouteActions(
  // First, validate the URL
  validateMiddleware,
  // Validate this page is not an admin page
  validateAdminPage,
  // Validate this page doesn't require compatibility mode
  validateCompatibilityMode,
  // Then, we Update the Alpine store
  updateStore,
  // Maybe fetch comments, if enabled
  fetchComments,
  // Update the history
  updateHistory,
  // Maybe update the admin bar
  updateAdminBar
)

// Set up the router. This also uses a middleware pattern.
setupRouter(
  // Setup event listener for clicks
  handleClickMiddleware
)

From here, you could extend what happens when a page is routed. Maybe you want to scan the page for code to highlight, or perhaps you want to change the content of the <head> tag to match the newly routed page. Maybe even introduce a caching layer. Regardless of what you need to-do, adding the actions needed is as simple as using addRouteAction or setupRouter.

Next steps

This was a brief overview of some of the key components I used to implement the nearly headless approach. If you’re interested in going deeper, I suggest that you take my course at WP Dev Academy. This course is a step-by-step guide on how to build a nearly headless WordPress website with modern tooling. I also suggest that you check out my nearly headless boilerplate that can help you get started on your own project.


The post How to Build a Nearly Headless WordPress Website appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.

Solving CLS Issues In A Next.js-Powered E-Commerce Website (Case Study)

Fairprice is one of the largest online grocery stores in Singapore. We are continuously looking out for areas of opportunities to improve the user’s online shopping experience. Performance is one of the core aspects to ensure our users are having a delightful user experience irrespective of their devices or network connection.

There are many key performance indicators (KPI) that measure different points during the lifecycle of the web page (such as TTFB, domInteractiveand onload), but these metrics don’t reflect how the end-user experiences the page.

We wanted to use a few KPIs which correspond closely to the actual experience of the end-users so we know that if any of those KPIs are not performing well, then it will be directly impacting the end-user experience. We found out user-centric performance metrics to be the perfect fit for this purpose.

There are many user-centric performance metrics to measure different points in a page’s life cycle such as FCP, LCP, FID, CLS, and so on. For this case study, we are mainly going to focus on CLS.

CLS measures the total score of all unexpected layout shifts happening between when the page starts loading and till it is unloaded.

Therefore having a low CLS value for a page ensures there are no random layout shifts causing user frustration. Barry Pollard has written an excellent in-depth article about CLS.

How We Discovered CLS Issue In Our Product Page

We use Lighthouse and WebPagetest as our synthetic testing tools for performance to measure CLS. We also use the web-vitals library to measure CLS for real users. Apart from that, we check the Google Search Console Core Web Vitals Report section to get an idea of any potential CLS issues in any of our pages. While exploring the report section, we found many URLs from the product detail page had more than 0.1 CLS value hinting there is some major layout shift event happening there.

Debugging CLS Issue Using Different Tools

Now that we know that there is a CLS issue on the product detail page, the next step was to identify which element was causing it. At first, we decided to run some tests using synthetic testing tools.

So we ran the lighthouse to check if it could find any element which could be triggering a major layout shift, it reported CLS to .004 which is quite low.

The Lighthouse report page has a diagnostic section. That also did not show any element causing a high CLS value.

Then we ran WebpageTest and decided to check the filmstrip view:

We find this feature very helpful since we can find out which element at which point in time caused the layout to shift. But when we run the test to see if any layout shifts are highlighted, there wasn’t anything contributing to the huge LCS:

The quirk with CLS is that it records individual layout shift scores during the entire lifespan of the page and adds them.

Note: How CLS is measured has been changed since June 2021.

Since Lighthouse and WebpageTest couldn’t detect any element that triggered a major layout shift which means it was happening after the initial page load possibly due to some user action. So we decided to use Web Vitals Google Chrome extension since it can record CLS on a page while the user is interacting with it. After performing different actions we found the layout shift score is getting increased when the user uses the image magnify feature.

I have also created a PR to the original repo so that other developers using this library can get rid of the CLS issue.

The Impact Of The Change

After the code was deployed to production, the CLS was fixed on the product details page and the number of pages impacted with CLS was reduced by 98%:

Since we used transform, it also helped to make the image magnify a smoother experience to the users.

Note: Paul Irish has written an excellent article on this topic.

Other Key Changes We Made For CLS

There are also some other issues we faced through many pages in our website which contribute to CLS. Let’s go through those elements and components and see how we tried to mitigate layout shifts arising from them.

  • Web-fonts:
    We have noticed that late loading of fonts causes user frustrations since the content flashes and it also causes some amount of layout shifts. To minimize this we have done few changes:

    • We have self-hosted the fonts instead of loading from 3rd party CDN.
    • We preload the fonts.
    • We use font-display optional.
  • Images:
    Missing height or width value in the image causes the element after the image to shift once the image is loaded. This ends up becoming a major contributor to CLS. Since we are using Next.js, we took advantage of the built-in image component called next/images. This component incorporates several image-related best practices. It is built on top of <img> HTML tag and can help to improve LCP and CLS. I highly recommend reading this RFC to find out the key features and advantages of using it.

  • Infinite Scroll:
    On our website, product listing pages have infinite scrolling. So initially, when users scroll to the bottom of the page they see a footer for a fraction of seconds before the next set of data is loaded, this causes layout shifts. To solve this we took few steps:

    • We call the API to load data even before the user reaches the absolute bottom of the list.
    • We have reserved enough space for the loading state and we show product skeletons during the loading status. So now when the user scrolls, they don’t see the footer for a fraction of seconds while the products are getting loaded.

Addy Osmani has written a detailed article on this approach which I highly recommend checking.

Key Takeaways
  • While Lighthouse and WebpageTest help to discover performance issues happening till page load, they can’t detect performance issues after page load.
  • Web Vitals extensions can detect CLS changes triggered by user interactions so if a page has a high CLS value but Lighthouse or WebpageTest reports low CLS then the Web Vitals extension can help to pinpoint the issue.
  • Google Search Console data is based on real users' data so that also can point to potential perf issues happening at any point in the life cycle of a page. Once an issue is detected and fixed, checking the report section again can help verify the effectiveness of the performance fix. The changes are reflected within days in the web vitals report section.
Final Thoughts

While CLS issues are comparatively harder to debug, using a combination of different tools till page load (Lighthouse, WebPageTest) and Web Vitals extension (after page load) can help us pinpoint the issue. It is also one of the metrics which is going through lots of active development to cover a wide range of scenarios and this means that how it is measured is going to be changed in the future. We are following https://web.dev/evolving-cls/ to know about any upcoming changes.

As for us, we are continuously working to improve other Core Web Vitals too. Recently, we have implemented responsive image preload and started serving images in WebP format which helped us to reduce 75% of image payload, reduce LCP by 62%, and Speed Index by 24%. You can read more details of optimization for improving LCP and Speed Index or follow our engineering blog to know about other exciting work we are doing.

We would like to thank Alex Castle for helping us debug the CLS issue on the product page and solve the quirks in the next/images implementation.

Replicating the Particles Animation from DNA Capital with Three.js

In this ALL YOUR HTML coding session you will learn how to recreate the beautiful particles animation from the website of DNA Capital using Three.js. The website was made by Immersive Garden.

This coding session was streamed live on October 17, 2021.

Check out the live demo.

Support: https://www.patreon.com/allyourhtml

Setup: https://gist.github.com/akella/a19954…

The post Replicating the Particles Animation from DNA Capital with Three.js appeared first on Codrops.

Dataweave 2.4.0 Dates Module Functions

DataWeave is a programming language designed for transforming data. It is the primary language of MuleSoft for data transformation and an expression language for components and connectors configuration.

Mulesoft released Dataweave 2.4.0 for Mule Version 4.4. The 2.4.0 version of DataWeave introduced many new features. In this post, we will see one of the newly introduced DataWeave modules.