WordPress Developer Ukraine, Kyiv
Get the current logged-in user data in WordPress

Get the current logged-in user data in WordPress

Get the current user in WordPress: wp_get_current_user() and friends Showing the name of the logged-in user, loading their own data, hiding a block from guests: almost every project needs the current user. WordPress has a small set of functions for it, and the only real pitfall is calling them too early, before WordPress knows who…
Register a custom post type in WordPress the right way

Register a custom post type in WordPress the right way

Register a custom post type in WordPress the right way WordPress has two built-in content types, posts and pages. As soon as a site needs structured content of another kind (portfolio items, events, team members, properties), putting it into posts with custom fields gets messy: the blog list mixes articles with team profiles, the editor…
WordPress wp_schedule_single_event(): One-Off Background Tasks with WP-Cron

WordPress wp_schedule_single_event(): One-Off Background Tasks with WP-C ...

One-off background tasks with wp_schedule_single_event() wp_schedule_event() creates tasks that repeat forever. Many tasks should run only once, at a certain time: a follow-up email a day after registration, a cleanup an hour after an import, a reminder before an event. wp_schedule_single_event() does that: it runs a hook once at the given time and removes the…
Enqueue scripts and styles correctly in WordPress

Enqueue scripts and styles correctly in WordPress

Enqueue scripts and styles correctly in WordPress Adding JavaScript and CSS with <script> and <link> tags right in header.php is one of the most common mistakes of developers who come to WordPress from static HTML. It works, but it bypasses the WordPress asset system: no dependencies (your script may run before jQuery), duplicates (a plugin…
WordPress wp_insert_term and wp_update_term: Manage Taxonomy Terms Programmatically

WordPress wp_insert_term and wp_update_term: Manage Taxonomy Terms Progr ...

Create, update and assign terms in code: wp_insert_term() and wp_set_post_terms() Imports and migrations need to create categories and other terms in code, often with a hierarchy, and then assign them to posts. WordPress has functions for both: wp_insert_term(), wp_update_term() and wp_delete_term() manage the terms, wp_set_post_terms() and wp_set_object_terms() attach them to posts. The details that matter…
WordPress Term Meta: add_term_meta, get_term_meta, and Custom Fields for Categories

WordPress Term Meta: add_term_meta, get_term_meta, and Custom Fields for ...

Term meta: custom fields for categories, tags and custom taxonomies Since WordPress 4.4 terms have their own meta table, and add_term_meta(), get_term_meta(), update_term_meta() and delete_term_meta() work like their post counterparts. Before that, plugins kept term data in options with keys like category_12_image. Term meta is the place for data that belongs to the term itself:…