
Create, register and use shortcodes in WordPress
18/03/2023Learn how to create and register your own WordPress shortcodes to add dynamic content to your posts and pages.
Since I started making web components I’ve come across a few use cases for checking for valid HTML elements.
It turns out that this is fairly easy to do. By creating an element and then converting it to a string representation we can match against “[object HTMLUnknownElement]” to check whether an element has been registered to customElements or exists by default.
function validHTML(element) {
return document.createElement(element.toUpperCase()).toString() != "[object HTMLUnknownElement]";
}
validHTML('div') // returns true
validHTML('dog') // returns false
validHTML('registeredComponent') // returns true
For example, if we remove the boolean operator and just return the string we would get the following:
validHTML('div') // returns [object HTMLDivElement]
validHTML('dog') // returns [object HTMLUnknownElement]
validHTML('registeredComponent') // returns [object HTMLElement]
Learn how to create and register your own WordPress shortcodes to add dynamic content to your posts and pages.
Learn how to improve code readability and performance by using guard clauses in JavaScript. Discover their benefits and best practices.
Learn the difference between implements and extends in TypeScript. Use Implements to implement interfaces and types, and extends to inherit from classes.
In this tutorial we will look at using YAML in PHP. Learn about Parsing and Writing YAML files using Symfony's YAML component.
Measuring code execution performance is an important way to identify bottlenecks. Use these methods in JavaScript to help optimise your code.
Find bottlenecks, optimise and clean your code, and speed up your apps by measuring the execution time of your PHP scripts using microtime.
Learn how to regenerate and update WordPress media and image sizes both programmatically (without plugin), and also with a handy plugin.
Ever seen constants like __DIR__ and __FILE__ being used in PHP? These are 'Magic Constants', and this is how we can use them.
Learn how to use event listeners to detect and handle single and multiple keypress events in JavaScript. Add modifier keys to your application!
“>alert(“XSS”)