• I was thinking of giving my authors the ability to add custom CSS and JavaScript to their pages by creating a custom meta box. Is this commonly done, or am I going about this all wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • It’s probably not too commonly done. The reasons behind it are more to do with security (for the JS at least).

    For CSS, it’s not too much of a big deal. Anyone that can do CSS Styling can add the styles inline anyway, so the need for extra CSS code is almost never.

    For JavaScript, rogue code or code that’s not quite so secure can cause security issues for the site, so unless you can really trust that your editors won’t do anything silly (hey, we are all capable of that) then I’d suggst not allowing it, and let your editors know that if they need any cusotm JavaScript code to send it to you where you can check it and upload it to some central location.

    Thread Starter b-rad

    (@b-rad)

    True, I suppose using the editor for CSS makes more sense, although aren’t there issues with the CSS being stripped out when switching between the visual and tag editor modes?

    I’m not really worried about the JavaScript idea of a meta box, although may I’ll restrict it to admins.

    Thread Starter b-rad

    (@b-rad)

    I see that as of 4.3, WordPress allows you to include inline CSS in the text editor:

    Ex: <p style="color:red">blah blah blah</p>

    But strips out a CSS block:

    Ex: <style>p {color:red;}</style>

    Now I know that style blocks belong in a stylesheet, but I wanted to know if there was a way to include a block in the editor. I’m assuming that a custom field or custom meta box would be a way around this, but it there another way to get a block of CSS to be accepted by the editor?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Meta Box for CSS and jQuery?’ is closed to new replies.