Categories
JAVASCRIPT TUTORIALS WORDPRESS

How To Enable Javascript Code In WordPress Page

WordPress CMS by default blocks any Javascript code from running as part of the website’s Page or Post. This is done to to prevent any malware attacks or website hijacking through vulnerabilities created by enabling Javascript on the WordPress Page and Post level.

However, it is still possible to enable running of Javascript if the WordPress website owner knows what he is doing. The website owner can enable Javascript on WordPress using two methods:

Method 1: Installing a third party WordPress Plugin

By installing an external WordPress Plugin that allows adding Javascript per post, any non technical WordPress site owner can also enable Javascript on the WordPress Posts and Pages level.

Method 2: By editing function.php file of the active WordPress Theme

In this method, you would need to ftp to your installed and currently active WordPress theme directory and look for the file called functions.php. You will then need to hook a new PHP function that gets loaded right after the WordPress Post’s <head> section gets loaded. Below is an example of how to write such a hook function in your functions.php file.

function wp_hook_js() {
 ?>
    <script type="text/javascript">
        //Add your Javascript code here
    <script>
 <?php
}

add_action('wp_head', 'wp_hook_js');

In the above code you can see our new function wp_hook_js() that contains our Javascript code. However, in order for this function to get called, we use the add_action() function. From the above code, you can see that we are hooking up our wp_hook_js() function to ‘wp_head’. This is a hook that gets called whenever a WordPress Post or Page gets loaded.

Thus by using either of these two methods i.e. by using a WordPress Plugin or by editing our theme’s function.php file and adding a hook function, we can ensure our Javascript code gets executed each time a WordPress Post or Page gets loaded.

In addition to this, you can add custom CSS to your post using “Additional CSS” option under Theme Customization option you get when you go to the “Appearance” option in the WordPress Admin dashboard.

This is all that is required to be done in order to get custom Javascript codes running at the WordPress Page or WordPress Post level. Hope this article was helpful in giving an insight on how to get it all working.

Until next time, happy coding 🙂 !!

Categories
CMS LAMP PHP TUTORIALS WEB SERVER WORDPRESS

What is WordPress?

WordPress is a software tool that one can use to create a website with ease. WordPress is often also called a Content Management System or CMS for short, because it provides a set of tools and user friendly interface to manage the website and its contents, like creating new posts, delete posts, add new users, remove existing users, change the style of the website etc.

Wordpress Logo

The ease at which one can create a website and manage it, without its user needing to have any technical knowledge or programming language makes WordPress one of the most popular website development and CMS software of choice.

Just how easy is it to use WordPress for website development?


In order to create a new website using WordPress, the creator is not required to have any programming background. There are several web hosting providers such as Namecheap, GoDaddy etc who provide web hosting services with One-Click WordPress installers built into their user’s Control Panel.

So, by just clicking a button, a user will be able to create a simple WordPress website. Of course a little bit of configuration needs to be done to ensure that the domain name that the user wants to use with the website is done. However, this is pretty straight forward and the web hosting providers do provide with sufficient tutorials and documentations on how to do this so it should not really be a bottleneck for non technical first time creator of a WordPress website.

How much does the WordPress software tool cost?

WordPress is an open source website development and CMS tool that is made available for free to its users. So, there is no cost one has to pay for using WordPress to create a website.

However having said that, a website needs to be stored in a web server and be made available to its users across the world. This web server will then be serving your WordPress web pages on the internet to its users throughout the day. This process is actually called as “Web Hosting“.

Theoretically, one can use your own computer to run (aka host) your website, but then you will need to ensure your computer is always switched on, connected to the internet and also not slowing down at any point in time. This means, you will not be able to use your computer for any other tasks that will slow down your computer.

So to avoid that, one will need to rent out a web server from any one of the various WordPress web hosting service providers. By doing so, the responsibility of ensuring that the website’s uptime i.e. your WordPress website’s web server is up and running 24/7 throughout the year will be taken care by those WordPress web hosting service providers.

Even though it may cost you a little bit to host your WordPress site on a 3rd party web hosting service providers, It is still considered a very good business decision to outsource such tasks to the service providers as then you can focus on your specific business growth activities knowing that your website’s uptime will never be compromised.

So now that we have a brief introduction to what a WordPress software tool is, we will just briefly discuss about some technical details of the WordPress. While a non technical person need not have to know any programming aspects of WordPress, having a little bit of introduction to what WordPress itself is made up of can be useful when he needs to get some technical help from any person in the future.

What is the Programming language used in WordPress?

WordPress is a PHP programming language based Content Management System (CMS). It is one of the most popular CMS used across the world. It powers more than 30% of the websites on the internet, and as a result of this popularity, it is often also the most targeted platform by hackers to try to find and exploit WordPress’s vulnerability. So one has to ensure that he keeps his WordPress website always updated with any security patches released by WordPress community.

What is the software stack used in WordPress?

While in the previous section, we described WordPress as a CMS written using PHP programming language, it also makes use of other additional technologies. These technologies clubbed together are often called as a software stack.

WordPressContent Management System (CMS) is primarily made of LAMP stack. LAMP stack stands for Linux, Apache, MySQl and PHP stack, where each of these components of the stack serves a specific purpose.

While we will discuss about each of these components of a WordPress stack in greater detail in future articles, here is a brief description of what each of this LAMP stack of WordPress stands for:

Linux – Linux is the Operating System that the webserver runs on.

Apache – Apache is the Web Server on which WordPress will typically run on.

MySQL – MySQL is the name of the database which is typically used by WordPress to store any website data as well as its content itself.

PHP – PHP is the programming language used to write WordPress software.

If you have read up to this point, you should now be having a decent understanding of what a WordPress software tool is, got an introduction to some new terminologies like CMS, Apache, MySQL, PHP etc.

In the future articles, we will start taking a deeper look into each of these components that make up a WordPress website, what their primary roles are in the functioning of WordPress, how their performance matters for the performance of your WordPress website as a whole and much more.

If you have any doubts after going through this article, or would like me to cover any specific point in more detail regarding WordPress, do leave a comment on this post below and I will make sure to discuss with you further on those topics.

See you in the next article!