I've noticed that WordPress seems a little loosey goosey when it comes to quoting styles in the HTML it generates. Sometimes WordPress uses single quotes, other times it uses double quotes

<link rel='next' title='An Example' href='http://example.com/foo/' />

<link rel="canonical" href="http://example.com/foo/" />

I know that single quote are, as of HTML5, technically "OK", but I'm weird and particular about how my HTML looks. Is there a way to tell WordPress to always use double quotes? If not, is there a plugin that might do this for me, or can someone point me to the appropriate do_action/apply_filter points so I can investigate this one my own?

  • @MarkKaplun Thank you for your attention, and it's always good to remind folks that HTML 5 was, in large part, an effort to unify the early HTML standards, browser behavior, and developer practices that existed up to that point (which included single, double, or NO quotes). However, labeling a single programmer's desire for a consistent quoting style as "OCD", "Wasting time", or "Pure esthetics" seems a little close minded and, at least from my point of view, rude. There are advantages for some teams (mainly around tooling) in simplifying the rendered source to use a consistent quote style. – Alan Storm Oct 10 '16 at 19:51
  • I appear to have offended you in some way @MarkKaplun -- I'm not sure what I did but I apologize for the offense. Re: your comments on HTML5, I'm not sure our views are that incompatible -- but section 2 of the working draft was always the part nearest and dearest to my heart. w3.org/TR/html-design-principles/#compatibility – Alan Storm Oct 11 '16 at 5:28
  • calling me "narrow minded" had probably done it :(. anyway I was around and following mozilla development when the whatgp group was established to develop html5 and the reasoning for it was as I said. In theory, while mostly the same this days, w3c is following the whatgp and and least for some time (not sure about now) the authoritative standard, which was followed by browsers, was the one published by the whatgp – Mark Kaplun Oct 11 '16 at 6:22

First of all, either quotes are as good as each other. See this question

There is no way you can do this with a plugin, action or filter. To achieve this you will have to do this manually by using the "find and replace" option on your IDE. I do not advise you to do this as:

  • You may end up breaking your wordpress core
  • You will loose all changes next time you will update your wordpress
  • You will have to go case by case as situations like these may appear:

echo <link rel='" . echo $bar . "' href="' . echo $foo . '";

in which case you will have to invert double quotes for single quotes and vice versa.

This will be very time consuming for what you will get in return.

As a matter of fact wordpress coding standards accept both quotation styles:

See Wordpress HTML Coding Standards on Quotes

| improve this answer | |
  • 1
    Thanks @db306 -- exactly what I wanted to know. Thanks for the WordPress cultural briefing ;) – Alan Storm Oct 10 '16 at 19:52
  • @Alan Storm -- No problem, glad to see that some people care about coding standards and global consistency. – db306 Oct 10 '16 at 21:13

How desperate are you to do this? This answer explains how to capture the final output, then you can use DOMDocument::loadHTML to load in the final output and re-emit with ::saveHTML which will output the quotes the way you like. It may also eat something else in the page, but it will sort out the quotes.

| improve this answer | |
  • yeh this kind of pointless craziness is actually the only way to do it properly. The only problematic aspect is that many pages are not validating properly and I am not sure if loadHTML will parse them correctly, or if there might be some other side effects – Mark Kaplun Oct 12 '16 at 9:05
  • I was going for the is it possible angle, not the is it sensible angle – Richard Oct 12 '16 at 9:42
  • +! for good information, but I've been down that road too many times to recommend it. DOMDocument's loadHTML is a fantastic resource for reading data, but it's can be inadvertently destructive when outputting the data back out. – Alan Storm Oct 12 '16 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.