close up shot of a typewriter
Photo by Markus Winkler on Pexels.com

Crafting My First WordPress Plugin with ChatGPT’s Assistance

I found some issues, I need simple solution which require minimum code impact, I prompt it and ChatGPT provide me the details.

After a prolonged hibernation from my blogging activities, I found myself back at the keyboard, itching to enhance my site’s functionality. Struggling with the limitations imposed by current themes, I sought a solution that would transcend these constraints. Recalling the versatility of WordPress hooks, I turned to an unconventional ally: ChatGPT. What ensued was nothing short of remarkable. With each my guided prompt, ChatGPT helps me in crafting a WordPress plugin tailored to my needs, resulting in a solution that exceeded my expectations. Let’s dig to the detail process step-by-step.


In short, my current blogging activities require a few key functionalities. Firstly, I yearned for a “duplicate” button for both “Pages” and “Posts” within the backend interface. Secondly, I sought to incorporate column headers displaying “Menu Order” for “Pages”. It’s very convenient if I could see the number listed up in the “Pages” back-end list which later use to construct menu navigation. I construct my blog navigation heavily on “Pages” structure. This is why menu order for the pages is so important for me. Lastly, I envisioned an enhancement to the block editor, enabling the addition of captions to featured images. I was a fan of Pexels for providing me the feature images, if you use that service, wordpress automatically fill-up caption text to include credits. But current block editor couldn’t show that caption text.

First Issue: To create “Duplicate” option in “Pages” and “Post” List.

After first code generated by ChatGPT, I implement it in my environment. However, as first try, obstacles arose. Then I follow-up with additional prompt below.

After some tweaks, the code finally succeded to add “duplicate” button to “Posts” and “Pages” list. The problem is because in other generated code (for feature image caption), there was a code that executed when page or post being rendered while duplicating the post/page. So I delete it and then everything is fine.

Second Issue: Showing header column for “Menu Order” for pages.

Onto the second requirement, I faced new challenges. Despite the initial roadblocks encountered, ChatGPT provided a solid foundation upon which to build. But sometimes needs to adjust your prompt to make sure he is not misunderstand about your requirements.

Through meticulous testing and refinement, I eventually achieved the desired outcome.

Column shall be sortable.

Placing after “Author” column

Needs to maintain Parent-Child when sorted.

Finally, the addition of column headers showcasing “Menu Order” breathed new life into my backend interface.

Third Issue: Featured image caption in block editor

Actually for this issue, ChatGPT already tried to give his best. But he still defeated by the condition that this solution required another workaround. I googled for the issue and found the thread discussing the same issue. So, I implement as per that suggestion and fix my problem.

Final Thoughts

My foray into plugin development with ChatGPT’s guidance has been nothing short of enlightening. While it remains clear that human advisory is crucial for refinement, ChatGPT serves as an invaluable tool for igniting innovation. For those seeking to bootstrap their coding endeavors, I wholeheartedly recommend leveraging the power of AI assistance. As for the complete code, it finds its home on my gist GitHub page below. Let me know your feedback. Cheers.

Complete code are as follow:


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Roketboy

Subscribe now to keep reading and get access to the full archive.

Continue reading