WordPress.org

Ready to get started?Download WordPress

Forums

<code class="box"> disappear when page saved? (9 posts)

  1. Truth
    Member
    Posted 8 years ago #

    I wanted to add a style to some of my codes so I have this

    <code class="box">

    but after I save the page, it becomes <code> and the class is not saved so I can't have the style for it. Any idea how to fix it?

    Thank you :)

  2. ladydelaluna
    Member
    Posted 8 years ago #

    you might need to create a div for it in your stylesheet, and call it something other than "code" such as "snippet" or something... then style the div inside the css, so that all you have to do is use <div id="snippet"> when entering code into your posts or pages...

    <code> will default to wordpress's way of showing code...

    There may be another way to change the default way WP shows code, but this is my offer for a solution ;)

  3. Truth
    Member
    Posted 8 years ago #

    Ohhhh. okok. thanks :)

    I'm using the <blockquote> tag outside the <code> tag now and I would like to use the blockquote tag for something else hence using a class for the code. I'll try out that solution if no one has a better idea on how to go about showing my class for the code tag. Thank you :)

  4. Karrde
    Member
    Posted 8 years ago #

    The <code> tag isn't HTML, so you can't give it a class as you could if it were, say, a <div>. You'll have to use the <div> method unless you're comfortable with hacking WordPress itself to modify its display method (which seems a waste of time when you could just do it via <div>).

  5. Truth
    Member
    Posted 8 years ago #

    @karrde: Can I use the blockquote tag with a class="code" instead?

  6. Karrde
    Member
    Posted 8 years ago #

    Uhm, I'm not sure. Try it and see :)

    I'm not sure on how WordPress parses the tags from its editor - I've never really looked into it terribly much.

  7. ladydelaluna
    Member
    Posted 8 years ago #

    if all you're wanting to do is have the "code" show up in blocktext format, then yes, you can do

    <blockquote><code>
    blahblahblah
    </code></blockquote>

    I THINK...

  8. Michael Bishop

    Posted 8 years ago #

    Are you trying to have more than one style for code? you can simply style code in your style sheet, much like blockquote.

    code {style: here}

    just note there's no . or # for it.

  9. Truth
    Member
    Posted 8 years ago #

    Yupz, for the short codes, I just want to wrap them in the usual code tag for some, I wanted them to add a style to them like my blockquote.. I think I get it now. Thanks for your help :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.