I'm working on a plugin that takes $content for a post and alters some of the HTML. Seems there are two common ways to accomplish this in WordPress - using jQuery or using PHP's DOMDocument. I'm wondering what the advantages/disadvantages of one over the other are?
I'm working on a plugin that takes $content for a post and alters some of the HTML. Seems there are two common ways to accomplish this in WordPress - using jQuery or using PHP's DOMDocument. I'm wondering what the advantages/disadvantages of one over the other are?
Share Improve this question asked Nov 3, 2019 at 14:47 davemackeydavemackey 3152 silver badges18 bronze badges1 Answer
Reset to default 2PHP is running on the server, JavaScript in the client.
This means PHP is faster (more resources), the result can be cached, and you have to test only one interpreter.
JavaScript – you don't really need jQuery for this – is more error prone, because of weird clients, blocked resources, or a more limited available memory. However it can respond to user input immediately without an extra page load.
If you have a situation in which both ways are leading to the same result, go for the server side.