WordPress.org

Ready to get started?Download WordPress

Forums

Copying Shortcodes and Loss of "Class" Attribute (4 posts)

  1. Colin Campbell
    Member
    Posted 1 year ago #

    So I've been working on rolling some shortcodes into one of my themes recently, and have run into this issue.

    I type out the shortcode in the Visual Editor. No problem.

    [shortcode att1="value1" class="some-class"]

    I select it, copy it, and paste it on to another line.

    [shortcode att1="value1"]

    BOOM! The attribute "class" is gone from sight, but the other attributes are still there.

    Is there something going on here behind the scenes when I paste it? Because if I then paste it into a plain-text editor, it copies the shortcode, including all attributes like it should.

    What's up with this? TinyMCE Bug, or am I missing something here?

    This happens even on a fresh install of WordPress 3.5.1 with the default theme and no plugins activated, and on multiple different servers, accessed using multiple browsers.

    I know this can be avoided by using a different attribute name, but I'm curious as to why it does this. Can't seem to find anything on it.

  2. FunnyBiscuit
    Member
    Posted 1 year ago #

    I met up with this sort of problem before.. I'm using [CKEditor for WordPress] plugin now, maybe you can try this?
    [sig moderated as per the Forum Rules]

  3. frizax
    Member
    Posted 1 year ago #

    This might be because WordPress Editor or other editors restrict "class" attribute due to formatting issues (class is HTML tag attribute). It will work when you paste this in HTML view of the editor.

  4. Colin Campbell
    Member
    Posted 1 year ago #

    Thanks for the replies!

    I know it probably isn't a best practice to be using the attribute "class" due it being confusing ( and I've already changed it to something else ), but what's interesting is that according to the Codex it is supported.

    Enclosing shortcodes support attributes in the same way as self-closing shortcodes. Here's an example of the caption_shortcode() improved to support a 'class' attribute

    Taken from the Shortcode API Codex Page

    I just wandered what the logic behind restricting it's use in the Visual Editor was since I can't imagine how it would really mess up the formatting since shortcodes aren't actual HTML elements.

Topic Closed

This topic has been closed to new replies.

About this Topic