Category: WordPress

  • Why I Still Bet on WordPress

    Why I Still Bet on WordPress

    Every few months, someone declares that WordPress is dead.

    I keep building outside it — and still coming back.

    Not because I’m stuck.

    Not because I don’t know better tools.

    But because after a decade of shipping real products, WordPress continues to win in places most comparisons ignore.

    Yes, I’ve built outside WordPress

    I’ve pulled Gutenberg out of WordPress entirely to build editor experiences. I’ve shipped headless setups where WordPress is nothing more than a content API. I’ve built React applications that never touch PHP. I’ve worked on projects where WordPress would have been the wrong choice — and I knew it.

    I’m not betting on WordPress because it’s all I know.

    What I got wrong about headless & decoupled frontends

    For a long time, I believed headless and fully decoupled frontends were the inevitable future — and not without reason. I chased cleaner architectures, React-first workflows, and the promise of total flexibility. In many cases, they delivered exactly that.

    What I got wrong was treating this approach as a default instead of a tool.

    The hidden cost wasn’t performance or technical complexity — it was friction. Previews broke. Editorial workflows slowed down. Simple changes required deploys. Teams gradually lost autonomy in ways that were easy to ignore at first.

    Headless isn’t the problem; uncritical adoption is. Over time, I learned that most projects don’t need maximum flexibility. They need reliability, ownership, and a stack that doesn’t fight back.

    That realization is a big part of why I still bet on WordPress today.

    What Gutenberg quietly got right

    Gutenberg’s value isn’t the editor — it’s the architecture underneath.

    Blocks are portable UI contracts. A block defines its structure, its attributes, its allowed variations. That definition travels with the content, not the theme. Switch themes, the content survives. Query blocks programmatically, the structure is already there. This is what years of shortcode chaos never gave us.

    Then there’s the shift toward declarative configuration. block.json and theme.json moved WordPress away from scattered PHP hooks toward predictable, tooling-friendly JSON. You can lint it, version it, generate it. It’s not perfect, but it’s a direction that finally aligns with how modern development works.

    The separation of structure from styling matters more than people realize. Classic WordPress tied content to presentation so tightly that switching themes meant rebuilding pages. Blocks broke that coupling. Structure lives in the content layer; styling lives in the theme. Long-term projects benefit from this in ways that aren’t obvious until year two or three.

    Blocks also scale better than their reputation suggests. Patterns, variations, and InnerBlocks let you build component systems without page builder bloat. Agencies are shipping block libraries now — not plugins full of shortcodes, but composable pieces with real contracts.

    Gutenberg is misunderstood by both its critics and its fans. Critics see it as a slow page builder chasing Elementor. Fans oversell it as a design tool for non-developers. Both miss the point. The real value is that WordPress finally has a content model that isn’t just HTML in a database column. That’s a foundation you can build on for years.

    Why I still bet on WordPress

    At this point in my career, I care less about architectural purity and more about leverage.

    WordPress gives me distribution, mature editorial workflows, and a content model that has finally caught up with modern development. It lets me choose when to decouple, when to go headless, and when to keep things boring — without forcing that decision upfront.

    Most platforms push you toward extremes. WordPress lets you stay in the middle longer, and that’s where most real projects live.

    I don’t bet on WordPress because it’s perfect. I bet on it because it compounds. The skills last. The ecosystem lasts. The content lasts. And with Gutenberg, the architecture finally does too.

  • Add Multiple Products to WooCommerce Cart at Once

    Add Multiple Products to WooCommerce Cart at Once

    We were working on a WooCommerce project that required us to add multiple products to the cart from a single click of a button.

    We wanted a solution from the JavaScript side, and we came up with the following code. This should fire when the “add to cart” button is clicked:

    Here’s a gist that contains the solution.

  • WP REST API can still cut it

    WP REST API can still cut it

    Most developers have used an API (and more specifically the REST API) in some point in their careers; and a WordPress developer is no exception. We may have used the WordPress REST API for fetching data from a remote WordPress instance, or update some record somewhere with authentication or to create a Headless WordPress site. Perhaps we simply used it within a Gutenberg block.

    GraphQL is an alternative to the REST API, and also a great technology. However, using GraphQL with WordPress requires the installation of a new plugin. If you are using GraphQL to merely solve the under-fetching/over-fetching problem for basic queries, you might want to continue reading this post.

    WP REST API 101

    The easiest way to play with the WP REST API is to visit any WordPress site’s URL followed by /wp-json. I’d recommend a REST client like Postman or Insomnia. In case you do not download these apps, you can visit the URL on your browser. If you go this route, however, I’d recommend an extension to view JSON data. You can find them on your Browser’s extensions library. Taking this site as example, let’s say you visit the following URL:

    https://muhammad.dev/wp-json

    You will get a huge chunk of JSON data. There will be multiple namespaces. I’d recommend you go explore the the WP namespace first:

    https://muhammad.dev/wp-json/wp/v2

    You will get the endpoints inside of the core WP namespace. Let’s look at the latests posts:

    https://muhammad.dev/wp-json/wp/v2/posts

    Solve over-fetching using _fields

    If you followed the last link, you would have seen a bunch of fields for the latest 10 posts. Let’s say you only need the title, and excerpt. Here comes the key part: you use the _fields URL parameter to limit the fields to just what you want:

    https://muhammad.dev/wp-json/wp/v2/posts?_fields=title,excerpt

    The above will only return the posts’ titles and excerpts. This would reduce the load time significantly since it’s much less data as compared to retrieving the entire dataset from the posts endpoint.

    Get the full categories, tags, and featured image

    Another “limitation” with the REST API is that you cannot see the name or slug of the attached category or tag for a post if you go to the /posts endpoint.

    The solution to this is to pass the _embed param to the URL.

    https://muhammad.dev/wp-json/wp/v2/posts?_embed

    The above will give you the terms (categories, tags) used for the posts. Additionally, you will also get the featured image details for the give post. This will save you from making multiple calls to the remote endpoint, thus saving time and money.

    Although this is not a full-on nested call like you can do with GraphQL, this is good enough for a lot of use cases.

    A note on using _fields and _embed

    As you try to use these tips, you would be tempted to use both the _fields and _embeds params in one call. You will notice that it is not possible to do so.

    When I tried the above scenario, it returned empty results. So, I followed this solution StackOverflow to get over this roadblock.

    TLDR;

    Perhaps you are discouraged from using the WP REST API because it fetches fields you do not need. Perhaps it is because the results do not contain the featured image URL or the category/tag name and slug. If so, then you might want to consider sticking to the REST API before looking elsewhere.

  • New to WordPress Development? Here’s a 2025 Guide!

    New to WordPress Development? Here’s a 2025 Guide!

    Precursor

    Let me start with a personal take.

    I started dabbling with WordPress 10 years ago in 2015.

    In that period, there have been changes several changes. Still, there have also been things that have stayed the same.

    I’ve learned an important trick; to develop foresight, you need to practice hindsight.

    Jane McGonigal

    Let’s focus on the fundamentals, first – the things that stood the test of time and will do in future.

    We can use WordPress for many purposes. It can serve as a tool builder, like a resumé maker. It can also be a platform or even a billboard. Nevertheless, the fundamental reason we use WordPress is for content.

    When we say content, it can mean many things – including Instagram reels or TikToks. However, with WP, content primarily means the written word. That’s what I believe the Word in WordPress stands for.

    Although, we can upload and embed videos and images, the power of words is what makes WordPress, well, powerful.

    So, it is a Content Management System as its core.

    The Foundations

    Now that we know what WordPress is (a CMS), let’s dive into what you need to learn to become a developer in the short term.

    By near term, I mean a quarter of a year. Let’s say you start now; you could hopefully become a Junior WordPress Developer by June 2025.

    These are the tools you need to master to get going:

    1. An understanding of the WordPress basics. What is a post and how does it differ from a page? What is a post type? What is a taxonomy? How do I change a theme or install a plugin? And so on.

      There is an endless list of questions you may have as you follow through. I recommend you befriend your friendliest AI tool to ask questions and get clarity.
    2. A Development Environment. Avoid working on projects without a dev environment if you can. Do not work on projects with just a single production site where all the work happens. I also recommend having a local WP environment. This way, all your development work is on your computer. You can do this while you are working. LocalWP and Studio by WP.com are both great for beginners.

      Think of it this way. Would you be doing carpentry at the location of your customer or at your work shed? I would do it at my work shed or a home office shed (remote work FTW). So, let’s use a local development environment.
    3. Basic Web Development. I would say you should possess the basics of HTML, CSS, and JavaScript. I am not a purist, so w3schools.com is a good resource for learning that. If you happen to be a purist, head over to mdn!
    4. Some backend knowledge. It is also good to know some PHP and MySQL. Or even the basic syntax and ideas are sufficient.

      Again, ChatGPT is your friend. Pester it with your questions and test yourself against it.

    Intermediate

    Now, we are getting to where most developers should get to. However, a lot of them will take a false path. Others will stop with the foundations. For instance, they will still use the Classic Editor. They will rely solely on a Page Builder. They will also stick to store bought themes and plugins without considering any customizations.

    WordPress Hooks (filters and actions) 🪝 are an important part of advancing as a WordPress developer. It’s crucial we learn it right – and practice it.

    Gutenberg was merged to core in 2018 and there has been a mixed reaction from the community. I believe it is about time (albeit a bit too late) to embrace the block editor with both arms.

    There are so many terms when it comes to the block editor. But keeping abreast of the nuances pays off handsomely in the long run.

    With that said, let me throw some words:

    1. Blocks – they can be core or custom
    2. Block Patterns
    3. Block Filters
    4. Block Styles
    5. Block Variations
    6. Block Plugins
    7. Block Themes and Full Site Editing
    8. Block Templates
    9. Reusable Blocks
    10. Dynamic Blocks – as opposed to Static Blocks

    I do not want to explain here what each means. Nor do I want to be considered an expert in critiquing the decisions that went into its nomenclature. You could learn a ton about these from fullsiteediting.com or through Google / ChatGPT.

    You can also learn from wpdevelopment.courses. Please note, it is a paid resource and I am a student of the course. The course helped me a ton to level up in block theme development. And no, I am not being paid to say this.

    ES2015+ or ES6 is also a decade old now. And React is 12 years old now; almost a teenager. The reason I mention it is so that we are aware its about time we learned these. So along with learning Gutenberg, it’s essential to also learn modern JS.

    Of course, here comes the other essentials like security best practices. Escaping, Sanitizing, Validating – the whole nine yards.

    An excellent resource is WPVIP’s course on security.

    It could take a year or more to get comfortable at this.

    Advanced

    You are in the big boy league now.

    It can take a several years to become great at WordPress.

    Courses from here are great to get good at some advanced WP concepts.

    Also, feel free to go through these best practices.

    The best way to become great, in my opinion, is to go through the works of the best people in the industry.

    For example, reading through WP Core or Gutenberg Core’s code on GitHub, perhaps reading through a major plugin’s code like Google Site Kit, or by contributing to core and other open source software yourself.

    An obvious way to get advanced is by working on large site rebuilds or plugins that touch many sites and has great impact.

    Closing Thoughts

    Do not forget about the community.

    You would be doing yourself a great favor by participating in dialog with the WordPress community, over on Twitter or at local events such as Meetups and WordCamps. A friend I made at a meetup 10 years ago is my almost like a mentor now!

    Of course, when you get to the advanced level, it’s good to contribute back to WordPress in the form of code, events, teaching, encouraging, documenting, organizing, volunteering, and so on.

    So, how do I get started?

    It depends on what you want to achieve with WordPres.

    If I were to give you one call to action, it would be that you register as a member of WordPress.org – you will hopefully look back and thank yourself that you did so.

    The more important CTA, however, is to head over learn.wordpress.org and choose your path!

    Closing Thoughts

    I initially set out to write about the WordPress ecosystem—the so-called bubble where outsiders often dismiss WordPress developers as “not real developers.” Instead of merely highlighting a problem, I decided to offer a solution: a practical roadmap to becoming a proficient WordPress developer. I hope this approach provides real value and inspires you to embrace the journey ahead.

    Thank you for reading this far.

  • Thinking in WordPress

    Thinking in WordPress

    WordPress is a handy blogging tool, a useful Content Management System or a capable web application framework. Whatever way you look at it, WordPress helps you solve problems in creative ways. In this article, I want to talk about how I approach projects and my methodology for problem-solving with WordPress. This is not an exhaustive list and one article wouldn’t do justice to the vastness of WordPress. I will try to add whatever pointers stand out among the decisions you would probably have to take.

    (more…)
  • Getting Started With Gutenberg By Creating Your Own Block

    Gutenberg is the future of WordPress, and it is just around the corner. Brace up for it by learning how to build your own custom Gutenberg block. I wrote this post for Smashing Magazine, which was published 10 days ago.

    (more…)
  • My Favorite WordPress Features

    My Favorite WordPress Features

    As you work with WordPress for some time, you begin to realize WordPress is much more than a blogging tool. Sometimes, even more than a regular CMS. In this post, I will talk about the different features/add-ons of WordPress and how you can utilize them for your next problem or project. Specifically, this post comes from my experience with WordPress and what I love about the different WordPress features.

    (more…)
  • Shortcodes and Meta Boxes in developing a WordPress theme

    I was fortunate to attend the meetup #4 titled ‘Meta boxes and Short Codes for Theme Development’. This event was organised by the WordPress Colombo Meetup group and held on 21 July 2016 at JKCS Auditorium, Colombo.

    WP meetup #4 (more…)

  • WordPress Colombo

    Ever since I started out with mtwoblog.wordpress.com I have been fascinated by the whole WordPress ecosystem. Among many factors like the platform, the themes, the plugins, it also largely includes the active, growing community behind WordPress. One such community is WordPress Colombo which is essentially a group of WP enthusiasts in Sri Lanka on meetup.com.

    WordPress Colombo
    WordPress Colombo

    (more…)