Tag: Coding

  • Reolved failed upload in WordPress post edit filter

    When adding an upload form to the post edit screen in WordPress admin, I found the upload to fail. The $_FILES array was empty.The reason was that by default, WordPress post edit form does not send files data. To fix that, we need to add enctype attribute to the form.Here is the code to do […]

  • How to customize PHP error message in WordPress

    WordPress displays a default error message when it encounters a PHP error- There has been a critical error on this website. Learn more about troubleshooting WordPress. Now this message is subtle, but still reveals 2 things- Your website has some error Your website is built on WordPress Now second point is usually fine unless you […]

  • How to change custom post permalink in WordPress

    I have struggled with this issue for years. I tried different ways but they always felt like hacks and gave inconsistent results most of the time. I also tried a popular plugin which broke my site. Whenever you add a custom post type in WordPress through code, there is no way to select a permalink […]

  • WordPress: Missing canonical tags on archive pages

    WordPress keeps surprising me even after more than a decade since I started using it. Today I came to know that WordPress only generates canonical tags for singular pages (posts & pages). WordPress does not add canonical tags to archive pages including author page, post type archives, taxonomy archives etc. So, how to add canonical […]

  • 404 pages getting redirected to home

    Today, I wasted major part of my day trying to figure out why my subfolder based WordPress multisite install is redirecting all 404 errors to the site’s home page. The problem turned out to be the constant “NOBLOGREDIRECT” which I defined in wp-config.php file. This constant ensures that in a multisite install, if anyone tries […]

  • Prevent Form Resubmission on Page Refresh

    We face a common issue on many websites that whenever a form submits to the same page, and then we refresh the page, the form data is submitted again. Sometimes the browser asks for confirmation, sometimes it does not. It becomes really frustrating if it causes an operation to happen twice. To prevent this on […]

  • Prevent Memory Leak in WordPress

    Recently I faced an issue of memory leak in one of my WordPress projects. I was running a function that was reading post meta and user metadata of thousands of objects. I thought reading data from MySQL is cheap in terms of processing power and memory, but it turned out it was causing my function […]

  • Fix Indentation Issue in Visual Studio Code

    Easily fix the tab size issue in Visual Studio Code by making this simple tweak in settings.

  • Correct Way to Manage Title Tags in WordPress

    Correct way to add or modify title tags in WordPress using the latest theme support feature and the filter hook to dynamically modify it on the fly.

  • How to count words in Unicode string using PHP

    How to count words in Unicode string using PHP

    How to count words in Unicode string using PHP? This sounds too easy. After all, PHP has so many string manipulation functions. To count words, we can simply use┬ástr_word_count and we are good to go. But there is a problem. While this function works fine for English strings, developers find this function unpredictable as sometimes […]