How to correctly format and use HTML code in WordPress blog posts?
Sometimes it is more feasible to manually add code to the posts in your WordPress site. Most of the time, the purpose of inserting code into a paragraph is so the post will be formatted as desired.
But what about all of those plugins out there that remove the need to code?
It’s true that there are available plugins that will allow you to insert code snippets and minimize errors, but you don’t necessarily need a plugin for something that can be easy to enter manually. Too many plugins loaded into the site can slow the site’s load time down. That’s not ideal in an era where everyone wants instant gratification. A slow website may lose visitors before even having a chance to convert them.
So if you have more than a few active plugins, you may want to enter certain pieces of code into your posts manually instead of slowing your website down.
Here at Templatetoaster WordPress website creator are some things you need to know about manually inserting code into WordPress posts:
- If the code is poorly formatted, WordPress will automatically “fix” it.
- If code is broken, WordPress will remove it.
- Anything that is entered into the HTML/Text Editor will be converted to HTML because that’s what WordPress wants to be there.
- Much of this doesn’t apply to WordPress.com blogs because WordPress.com won’t allow you to publish PHP, JavaScript, or anything other than HTML. If you integrate HTML, it has to be written properly because there is no correction of broken or incorrect code.
- Codes within a paragraph like <code>wp_title()</code> distinguish natural language from computer code, which is a significant part of the purpose behind manually inputting these snippets.
Non-HTML Appearing as Code
When you insert code into the post under the “text” tab in the post editor, it is possible that WordPress will use autocorrect. It depends on if you use the HTML or visual editor when inputting this code. If you enter code into the visual editor, then it is going to see the code as ordinary text. In this case, WordPress may automatically convert something like < and > to < and >. This is the “fix” that was mentioned in #1 above. This is so the web browser doesn’t interpret the code, which is common in older versions of WordPress. If an HTML tag was placed in the HTML editor, the characters are not converted, so you have to make sure what you enter is correct or you could be facing a distorted layout.
If you want non-html text to be seen as code within a paragraph, you will need to go to header.php in your theme directory. You can go to the
[highlight]<code><div class = “header”></code>[/highlight]
of the template file so you can change your heading. The heading is going to look like <code><h1></code>. However, WordPress is going to think that you are using the tag for formatting reasons, so its autocorrect function won’t touch it. A web browser looks at that code and all it sees is the beginning of an <h1> tag, which causes a huge mess for your layout.
It is possible to keep this happening by using extended characters that aren’t seen by a web browser as being the beginning and end of an HTML tag. The following are some extended characters you can use to format your posts:
You can use these extensions in your design and make it fun. For instance, you might want the shamrock to separate categories like this:
Books ♣ Music ♣ Movies
To achieve that effect, you would use
[highlight]</php the_category( ‘ ♣ ‘) ?>[/highlight]
You will read about more character extensions later in this post.
[call_to_action color=”gray” button_icon=”download” button_icon_position=”left” button_text=”Download Now” button_url=”https://templatetoaster.com/download” button_color=”violet”]
Make stunning WordPress themes in minutes with TemplateToaster Html website creator
[/call_to_action]
Hyperlinking Within a Paragraph
When you type http:// into a WordPress post, WordPress automatically turns it into a link. WordPress does have an in-post linking feature. You can highlight text, click the link icon in the kitchen sink, insert your link, tell it if you want the link to open in a new window, and you save it. You can also apply a link from the tool that pops up in the post without having to go into the original link box. You can use it whichever way you are comfortable.
However, there may be times where you find yourself having to hyperlink manually to a specific post. If you have to do that, the code is
[highlight]<code>http : / / yourpost.com/ index.php?p=453</code>[/highlight]
The /: is the forward slash (/) character extension or entity.
More Extended Characters to Use in Your Post
You saw the list of character extensions or entities earlier in this post, so here are some more that you can use:
- ☆ = ☆
- & = &
- " = “
- © = ©
- @ = @
And here are even more:
Using Code for Styling
One word of warning: If a line of code is long, it’s going to run off of the page. You have to keep it from running off of the screen, but you have to figure out where to put the line breaks using <p>. Those experienced with coding will know where to put these breaks without interfering with the code’s purpose. If you are new to coding, you can experiment and learn.
If you want to style your fonts, you will need to go to style.css in your theme directory. You will see code that begins with pre, code{. It is here that you will be able to change your font size and font color.
When Smart Quotes start causing you issues, it is usually because of WordPress’s autocorrect feature. Sometimes the issue is the result of pasting content from word processing software to the post editor. But regardless of where the quote came from, a straight quote may be converted to the quotation marks that are set within the installation language of the wp-config file in your theme directory. This can happen if the quotes have been written in the HTML editor or the visual editor.
The good news is that you can go to the HTML post editor and use <code> or <pre> to wrap the quotes and solve the problem.
You Can Code
So there you have different ways you can integrate HTML into your posts. You can make non-HTML behave like code, integrate extensions, style using code, and even troubleshoot issues by manually entering snippets instead of having to install plugins to do it for you. It doesn’t matter if you have a lot of coding experience or not. You can experiment and learn how to create certain stylings or behaviors with the integration of simple snippets. Just make sure you save the original coding before making changes so you can restore the original in the case an error occurs.
[call_to_action color=”gray” button_icon=”download” button_icon_position=”left” button_text=”Download Now” button_url=”https://templatetoaster.com/download” button_color=”violet”]
Best drag and drop website builder
[/call_to_action]
Build a Stunning Website in Minutes with TemplateToaster Website Builder
Create Your Own Website Now