There are several ways to deal with this problem.
You could have a look for some syntax highlighter plugin, those will also bring you coloured text with highlighted keywords etc. pp. This is probably nice, if you use code quite often. I use SyntaxHighlighter Evolved.
If you want to do this by hand, <code>
is probably the HTML-element you want to use, just like Stack Overflow does, too. It´s “designed” to be used that way (and understood as code from a semantical view, too).
If you want to prevent line breaks, you can add this to your CSS:
code { white-space: nowrap; }
You have to use this in the text view of the editor though, as the WYSIWYG version would probably strap it out.
You can get around that by defining a shortcode for your code-tag. You will find lots of examples for that around the web.
Related Posts:
- disable WP automatically inserted line breaks after an image
- Remove hidden formatting when user paste text from MS Word into TinyMCE
- Automatically added brs and paragraphs?
- Number format for wp_count_posts()
- Unautop / Sanitize content added to a post through a plugin
- Format the Layout of Images In The Edit Post Textarea?
- Posting blog entries in screenplay format
- Pasting formatted text from MS-Word
- All images on one line for each post
- How can I change the date format of the revision list?
- Post formatting bug in WordPress
- Theme does not respect spaces between paragraphs in pages
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Turn a URL into an Attachment / Post ID
- Allow variable amount of comments before pagination
- How to get the number of posts in a selected category?
- How to cache a shortcode functions output?
- Check if post has children or not
- Attach pdf file to custom post type
- How to call function within a page/post, to dynamically generate content?
- Post Size Limit
- HTML code in Custom field
- Count singular post views automatically
- Looping through posts per category gives same posts for each category
- how to hide specific post from google search
- Accessing $post variable from template part
- Programmatically inserting page breaks
- get_terms parent for current product only
- How can I extract the URL of a link from a post?
- Auto set Post to Specific Categories
- How can I control multiple editing of wordpress posts?
- How to Set Featured image In WordPress without Showing it into Post?
- Adding a cancel button to edit post screen
- Strange problems when I try to insert HTML\XML code snippet in my posts
- How can I list random authors from current post category?
- pagination hook doesn’t work with search results
- Tumblr-like Post Types for WordPress
- While in “the loop”, detect if a post is the most recent
- Edit Post VS Custom Form
- Templating of a specific post ID
- Can’t Delete or find a blog post (unknown)
- List posts in a given category
- Child_of not displaying all children posts.. via get_posts
- Append class to posts page
- Prevent additional top level categories but allow more children
- Error after upgrading WP from 4.0.6 -> 4.4.2: empty value in wp_post_types[‘post’]
- What’s the best way to render Visual Composer in posts, not pages?
- Trying to use AngularJS with WordPress without any API
- Showing author page if user has no post
- the_permalink() not working in a root installation
- Call Web Services on post first publish
- Get Value of Post before
- Fixing paragraph spacing in posts
- Customize rel=canonical tag for single blog post
- Make a vertical dynamic list of posts in alphabetically order and in columns [closed]
- Display posts of specific category term
- Widget that shows categories with posts numbers
- Run query_posts if SESSION is empty?
- Relative number of post in category
- Why can’t publish posts with too much text?
- How to save posts position on homepage after random function?
- How to embed custom HTML code with no plugins?
- Display in category ( taxonomy) a number of post that I want
- How to store array in usermeta in wordpress
- Setting limit to posts or page creation
- write a post on user registration
- Can Permalink structure of %postname%/%post_id% improve performance
- post/page content
- Help on conditional statement to accompany wp_insert_post function please?
- How to automatically share posts on facebook?
- Merge get_comments & get_posts into a single query
- Is there a way to categorize a list posts all at once?
- Display “no post” message
- Every time I try accessing a post it redirects me to the feed
- On the online version of my blog posts disappear
- Bulk Post update_post_meta
- More Than 50K Categories and WordPress Admin Panel Stop Showing Categories and Posts
- Hiding the name of the user who is currently editing
- allow editor/author to publish others posts but not publish their own
- Why does media_handle_sideload upload to last month’s folder?
- Re-order Category Meta-data
- Slug collision between page, taxonomy and custom post type
- Populate a drop down list with post titles across a multisite network
- including 404 page in post page
- Random order of the 5 most popular posts
- Posts only showing on /localhost/wordpress/ and not on other pages
- How to change number of posts shown on homepage vs other pages?
- Posts are printed twice
- Displaying Results From Custom Taxonomy Query
- find posts with exactly 3/4 categories
- Custom filter on all post page (admin backend)
- Displaying only posts from a certain category on my custom page template
- How can I create a menu items from meta box based on users input
- How can I count articles retrieved by tags
- WordPress strips some attributes for author posts
- Custom post page has attributes of latest post [closed]
- get value from post to sidebar
- How to make “my posts” page
- How to have 2 posting pages on a blog
- How to make the Post Author name fixed as “Editorial Staff” even if there are multiple authors?