background preloader

Dev

Facebook Twitter

Create WordPress Shortcodes. WordPress shortcodes are super handy, especially when handing off a WordPress-based website to a client.

Create WordPress Shortcodes

The alternative to using shortcodes is creating complicated templates, and even then, you cannot adequately replace what shortcodes can do. I recently needed to implement a new shortcode for the Mozilla Hacks blog and was happy to learn how simple the WordPress API makes creating new shortcodes! Let me show you how to create your own WordPress shortcodes!

First you start by creating a function within your theme's functions.php file. The function should return a string which replaces the shortcode within the rendered content. Function my_shortcode_routine($args) { $return = ''; return $return;} Remember that your function shouldn't echo; a string must be returned. After your function has been created, you can use WordPress' add_shortcode function to register the shortcode. Add_shortcode('shortcode_name', 'my_shortcode_routine'); [shortcode_name key1="value1" key2="value2"] Older Newer.

Widgets

Taxonomy and custom post. Do-It-Yourself Caching Methods With WordPress. Advertisement There are different ways to make your website faster: specialized plugins to cache entire rendered HTML pages, plugins to cache all SQL queries and data objects, plugins to minimize JavaScript and CSS files and even some server-side solutions.

Do-It-Yourself Caching Methods With WordPress

But even if you use such plugins, using internal caching methods for objects and database results is a good development practice, so that your plugin doesn’t depend on which cache plugins the end user has. Your plugin needs to be fast on its own, not depending on other plugins to do the dirty work. And if you think you need to write your own cache handling code, you are wrong. WordPress comes with everything you need to quickly implement varying degrees of data caching. WordPress implements two different caching methods: Non-persistent The data remains in the cache during the loading of the page. Non-Persistent Cache Example Every time you call this function for the same post ID, an SQL query will be executed. Important Notes Raw Widget. WordPress Essentials: The Definitive Guide To WordPress Hooks.

How To Create Custom Post Meta Boxes In WordPress. Advertisement Meet SmashingConf San Francisco 2017, featuring front-end ingredients, UX recipes and design beats from the hidden corners of the web.

How To Create Custom Post Meta Boxes In WordPress

Only practical, real-life techniques that you can learn from. Get your ticket! What seems like one of the most complicated bits of functionality in WordPress is adding meta boxes to the post editing screen. This complexity only grows as more and more tutorials are written on the process with weird loops and arrays. Creating custom meta boxes is extremely simple, at least it is once you’ve created your first one using the tools baked into WordPress’ core code. Creating meta boxes.Using meta boxes with any post type.Handling data validation.Saving custom meta data.Retrieving custom meta data on the front end.

Note: When I use the term “post” throughout this tutorial, I’m referring to a post of any post type, not just the default blog post type bundled with WordPress. A post meta box is a draggable box shown on the post editing screen. (al) WordPress Essentials: How To Create A WordPress Plugin - Smashing WordPress. Developing WordPress Locally With MAMP - Smashing WordPress. Quick summary ↬ Local development refers to the process of building a website or Web application from the comfort of a virtual server, and not needing to be connected to the Internet in order to run PHP and MySQL or even to test a contact form.

Developing WordPress Locally With MAMP - Smashing WordPress

One of the most annoying parts of development, at least for me, is the constant cycle of edit, save, upload and refresh, which, depending on bandwidth and traffic, can turn a menial task into a nightmare. Local development refers to the process of building a website or Web application from the comfort of a virtual server, and not needing to be connected to the Internet in order to run PHP and MySQL or even to test a contact form. One of the most annoying parts of development, at least for me, is the constant cycle of edit, save, upload and refresh, which, depending on bandwidth and traffic, can turn a menial task into a nightmare. Further Reading on SmashingMag: The Local Server More after jump!

MAMP and MAMP Pro are on the installation disc image. WordPress Essentials: Interacting With The WordPress Database - Smashing WordPress. Advertisement While you already use many functions in WordPress to communicate with the database, there is an easy and safe way to do this directly, using the $wpdb class.

WordPress Essentials: Interacting With The WordPress Database - Smashing WordPress

Built on the great ezSQL class1 by Justin Vincent, $wpdb enables you to address queries to any table in your database, and it also helps you handle the returned data. Because this functionality is built into WordPress, there is no need to open a separate database connection (in which case, you would be duplicating code), and there is no need to perform hacks such as modifying a result set after it has been queried. The $wpdb class modularizes and automates a lot of database-related tasks. In this article, I will show you how to get started with the $wpdb class, how to retrieve data from your WordPress database and how to run more advanced queries that update or delete something in the database.

Getting Started <? As you can see, this is a basic SQL query, with some PHP wrapped around it. Get_results() <?