Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to add simple JavaScript code in a single WordPress post/page

In addition to HTML and CSS, Javascript is something that every web developer should be involved in. This programming language is quite easy to learn, yet it will allow you to program your website and expand its functionality. Every modern browser supports JavaScript and no one will ask you to install additional browser plugins in order to get the content.

Even if you don’t speak JavaScript language fluently, sooner or later you will stumble upon its traces in WordPress. Your theme will use it, your plugins will use it and you will find it very useful if you try to expand your site and make it more user-friendly.

Adding any JavaScript Code in #WordPress is really easy. Just make sure to include the proper tag. Click to tweet

There are endless possibilities with JavaScript. Just to show you an example, this is how you can add extra content to copied text with JavaScript.

You don’t have to know how to code to take advantage of scripts on your WordPress website. You can easily find a code on the web, just like the one we have shown you and embed it where needed. But you will have to know how to add the code in your WordPress correctly.

Don’t worry; it is really simple and you’ll have your code executed in a minute.

Add a simple JavaScript code:

If you have a small piece of code which you only want to execute in one post/page, you really shouldn’t have problems with that. All you have to do is take the code and paste it in your Text Editor.

What you need to have in mind is that JavaScript code must be embedded within corresponding tags in order for it to work. If you take the code and leave out those tags, your code will not run, but instead, it will be displayed in your post as a regular text.

Here’s an example:


Another simple example will change the text in paragraph once a user clicks on the button:

Change this text by clicking on the button.

Change this text by clicking on the button.

In some case,s it will be enough just to enter the code directly into a post, like in previous examples. Usually, if you’re working on a theme or a plugin, you will need a larger block of code which will do something for your site. If you have browsed your theme’s and plugin’s directories, you have probably seen that JavaScript codes are stored in separate files. If the code is stored in another file, you will need to include that file on the page where you want your code to be executed.

The post How to add simple JavaScript code in a single WordPress post/page appeared first on WP Loop.



This post first appeared on WP Loop, please read the originial post: here

Share the post

How to add simple JavaScript code in a single WordPress post/page

×

Subscribe to Wp Loop

Get updates delivered right to your inbox!

Thank you for your subscription

×