WordPress.org

Support

Support » Themes and Templates » code in the post

code in the post

  • for some reason I am not able style the code tag. Unfortunately, for some reason, my code comes out as monospaced, but without a background color. example below

    http://oliverwolfson.com/mel-write-obj-sequence/

    I tried styling the code by putting in the following CSS. But nothing changed.

    code {
    	color: blue;
    	background-color: #EEEEEE;
    
    	}

    any ideas on this one?

Viewing 9 replies - 1 through 9 (of 9 total)
  • looking into your css i found that you put .code

    .code {
    	color: dimgray;
    	font-family: courier, serif;
    	background-color: #EEEEEE;
    	padding: 10px;
    	border: 1px solid #888888;
    	margin: 0 20px 0 20px;
    	width: 530px;
    }

    remove “.” like this

    code {
    	color: dimgray;
    	font-family: courier, serif;
    	background-color: #EEEEEE;
    	padding: 10px;
    	border: 1px solid #888888;
    	margin: 0 20px 0 20px;
    	width: 530px;
    }

    Thank you for your reply.

    Actually the .code is a class (below) that I use to style code. That works fine and gives me the look I want. The problem is that when I copy and paste this code to the program that I use the code in, I always get errors.

    <div class="code">

    anyway, today I was experimenting with using the built-in code tag (below), and that seems to work well. I can copy and paste code and it seems to work. My problem is that I am unable to style the code.

    <code>

    I already tried doing what you suggested but it made no difference.

    Here is an example of both my .code class and the built-in code tag in action. the code with the white background is the default, with gray bg is my custom style.

    http://oliverwolfson.com/mel-renaming/

    Michael
    Moderator

    @alchymyth

    your first attempt should work:

    code {color: blue;
    background-color: #eeeeee;}

    have you tried refreshing the browser cache by pressing CTRL and F5 simultaniously ?

    just be aware that not all this text of your post is within ‘code’ – the paragraph tags seem to break it:

    int $i;

    string $rename[] = ls -sl;
    int $selSize = size $rename;

    for ($i =0; $i <$selSize ; $i++){

    rename ($rename[$i]) (“newName_” + ($i +1));

    }

    If you want to show code in your posts, you might consider a syntax highlighter plugin, f.i. http://wordpress.org/extend/plugins/syntaxhighlighter/

    yea it’s strange, this is the post that is within the code tags (Below). i tried clearing the cash, but there was no change.

    I’ll try highlighter! But will that solve the issue of code, Which is cut and pasted giving me errors? that is really the problem anyway as i can style the code any way i want, with a div. It just needs to easily paste into a script and work.

    <code>
    
    int $i;
    
    string $rename[] = <code>ls -sl</code>;
    int $selSize = <code>size $rename</code>;
    
    for ($i =0; $i <$selSize ; $i++){
    
    rename ($rename[$i])  ("newName_" + ($i +1));
    
    }
    </code>

    This seems like a strange problem. Thanks for the suggestions! Please let me know if anyone has insight.

    Are you using the visual editor, or the HTML editor? The latter is recomended if you’re posting code, as the visual editor (TinyMCE) will break the code.

    thanks, but yes I am using the HTML editor. still somehow the code is broken though. I must be doing something wrong, right?

    Question: is there something I need to do with text that I want to be displayed as code when writing HTML? Is there something that I need to do with basic HTML or CSS to style text so that it can be used properly as code? Because if I could do that I wouldn’t have to worry about the code tag apparently been broken in my WordPress set up.

    okay, I think that I fixed it. Should have read the Codex a bit more closely. Using the <pre> before my div seems to have fixed the problem.

    http://codex.wordpress.org/Writing_Code_in_Your_Posts#Using_PRE

    Just to be clear, the problem fixed is: I can now cut and paste code styled with my custom div, and it works fine, apparently.

    I still cannot figure out how to style the built-in code tag.

    Anyway, thanks for all the suggestions.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘code in the post’ is closed to new replies.