Using Claude to Code a WordPress Plugin

Niall McNulty
3 min readJul 23, 2024

--

I’m a long-time WordPress enthusiast and have been using it for blogging for close to 20 years. I’ve often found myself wishing for specific functionalities that weren’t readily available in existing plugins. However, my lack of coding skills was a barrier. Recently, I’ve been coding with AI, specifically Anthropic’s Claude AI (Sonnet 3.5 version), and it has a superb ability to generate and explain code through its artifact feature.

Artifact window showing the Python code

I had a simple need: I wanted a way to easily export my WordPress posts to Word documents, preserving formatting and excluding unnecessary elements like related post suggestions.

Enter Claude AI as my personal code assistant. What sets Claude apart, particularly for non-coders like myself, is its artifact feature. This allows Claude to present large code snippets or complex files in a structured, easy-to-understand format.

The Development Process

My interaction with Claude began by explaining my plugin concept. Claude understood the requirement and started providing code snippets and explanations tailored to my level of understanding (low — it explained things step by step for me).

The development process was iterative. I would ask Claude for a piece of functionality and receive a code artifact, and then we’d refine it based on my needs or any issues that arose. This back-and-forth felt less like traditional coding and more like a collaborative problem-solving session. Maybe this is more like the pair-programming concept coders use to learn a new concept or language.

Steps I followed to create the plugin

Setting up the Development Environment

Claude guided me through:

  • Installing Composer, a dependency management tool for PHP
  • Creating the correct directory structure for a WordPress plugin

Core Plugin Development

With Claude’s help, I was able to:

  • Write the main PHP file for the plugin
  • Implement the export functionality using the PHPWord library
  • Add an export button to WordPress posts

Styling and User Interface

Claude provided CSS code to style the export button, and we even tweaked it to match Microsoft Word’s branding colours.

Troubleshooting and Refinement

As issues arose, such as unwanted content being exported or formatting problems, Claude offered solutions. We worked through content filtering challenges and fine-tuned the exported document format.

One significant hurdle was adapting the development process to my shared hosting environment. Claude provided alternative methods for installing dependencies and testing the plugin.

We also tackled WordPress-specific coding practices, ensuring the plugin adhered to best practices and security standards.

The Final Product

A fully functional WordPress plugin added an “Export to Word” button to each post, generating a well-formatted Word document with the post’s content. Seeing my idea come to life through code was excellent as a non-coder.

My very first WordPress plugin

Lessons Learned

This experience taught me several lessons:

  1. AI can significantly lower the barrier to entry for software development.
  2. Clear communication with AI assistants is critical to getting useful results.
  3. Coding projects can be approached iteratively, solving one problem at a time.

While I may not be a professional developer, I now have the confidence to approach coding projects that once seemed out of reach. Combining your domain knowledge and AI’s coding capabilities can lead to innovative solutions tailored to your needs. I’m excited about the possibilities of building with AI!

Here’s the GitHub repo:

--

--

Niall McNulty

Product Lead building Edtech solutions and scalable AI-content products. Publisher and author, now writing about using technology to create meaningful impact.