Categories
Blog Tips

How to extract attributes from an HTML string in PHP (without using RegEx)

Say you have an <a>, <link> or other HTML element and you need to extract its href (or other) attribute. You can extract those values using DOMDocument quite easily: Link to Repl.it PHP: DOMDocument

Categories
Tips

HTML’s forgotten native accordion: styling the details/summary element

As frontend developers or designers, many times we’re requierd to design or implement accordion-style components. While there are plenty of libraries out there, the easiest way to accomplish the same results without adding bloat is to use the details HTML element.

Categories
Tips

How to maintain the aspect ratio of an element with CSS

Still an experimental feature, but soon we will be able to set an aspect ratio to any HTML element via CSS, without any padding hacks!

Categories
Tips

Enable Custom Post Order via code in WordPress

Recently I enabled the great Simple Custom Post Order (SCPO) plugin in a bunch of sites. After you activate it you can go into its settings and enable sorting for all posts, custom post types, taxonomies, etc. We had a particular case though. At my current job, we manage a network of nearly 200 WordPress […]

Categories
Blog Tips

How to remove captions from Instagram embeds in WordPress

This is a simple code snippet to achieve just that in Instagram embeds, via shortcode or using Gutenberg. [instagram url=https://www.instagram.com/p/B1WjYcxCmHp/ hidecaption=true] You can achieve the same effect in single embeds by using the following shortcode Here’s the result YouTube Use this snippet if you want to achieve a similar result wit YouTube embeds: Has this […]

Categories
Tips

How to iterate a list in batches using Twig (or plain PHP)

Recently I had to loop through a series of elements in a WordPress template (thanks Timber), which happened to be using Bootstrap. If you ever used Bootstrap, you are familiar with the following markup: The problem here is very common. You have to: Loop every 3/4/n items. Insert a separator or whatever every 3/4/n items.

Categories
Apps/Tools Tips

How to fix: MySQL not starting on MAMP (Pro)

I recently had to install MAMP Pro, in order to do some separate work from my Laravel Homestead VM. After a weird Mac crash, MAMP would no longer start the MySQL server. This was the data from the logs: To fix this, go to MAMP, File > Edit Template > MySQL > [version] and add the line […]

Categories
Tips

How to open a chromeless Chrome browser window on macOS

This is a great tip to run apps on separate windows or just for taking cool app screenshots, like this: How to open a chromless window Open Terminal app and type: Where [URL] is the desired URL. e.g: If you’re curious about what those flags do, -n “Open a new instance of the application even […]

Categories
Tips

Nerdtip #356: hide profile visit data on Linkedin

Today I was bored checking someone’s Linkedin profile page when a friend mentioned that that person was going to know that I visited it. I thought, that’s weird, Linkedin doesn’t tell me who visited my profile. After a while going through settings, I notice theres an option that lets you hide that information. It’s worth mentioning that it works […]

Categories
Tips

Run a simple HTTP server with one command line

Recently someone told me this great and simple trick on how to run an HTTP web server with just one command line. This is useful for a million things, but I use it for prototyping and avoid same-origin policy in Chrome.