5 most useful and important WordPress functions

The most important WordPress functions allow you to customize your site's appearance and functionalities. This way, you can, for example, include new fonts on your website, remove scripts, and disable the "continue reading" feature. Check out this article to see how to make such changes.

the most useful and importante wordpress functions

See what 1400+ marketers had to say about the top marketing trends for 2024.

WordPress is the favorite CMS (Content Management System) for bloggers and companies because it is easy to use. Also, customizing it is a big part of the platform’s appeal.

That is why a large portion of the internet’s websites are built on this system. To properly customize your website, though, learning the most important WordPress functions is essential.

However, to learn how to personalize that part of your WordPress site accurately, you first need to understand what functions are and what they can do to your website.

We will look into the definition of function and talk about some useful tricks regarding them. Ready to learn? In this guide, you will understand:

Find out the answers to your WordPress functions questions!

Download this post by entering your email below

Do not worry, we do not spam.

What are WordPress functions?

Before we get started on some key WordPress functions, we need to understand how they work and why they are relevant. WordPress is built on PHP, a general-purpose scripting language that meets web development needs.

PHP is especially useful to create content management systems like WordPress because it enables interaction with a database and data fetching, outputting it for the user as HTML.

WordPress’ tags and functions are all built on PHP, and they are what makes this CMS so great.

Anyone knowing just a bit of coding can easily change PHP scripts, which are highly flexible. That allows owners to adjust each element on their WordPress websites.

Now that you know a little more about PHP and its relationship with WordPress, it is time to understand the functions.php file, which we will customize in this tutorial.

Every WordPress template comes with a pre-written functions.php file. It works like a plugin already installed on your WordPress hosting.

You can modify the functions.php file by using PHP code to add features or change defaults defined by your WordPress theme.

That is why editing this file can affect your WordPress configuration. With simple changes in functions.php, your theme can, for example, receive Google Fonts.

You can also pull all metadata from a blogpost or detect if a visitor is using a computer or a mobile device.

How do WordPress functions work?

To make changes in your functions.php file, you first need to find it. The functions file is always within your WordPress theme. But not all changes made to a WordPress website need to be done in the functions.php file.

Actually, when you want to add functionalities or customize your website, the best way to do so usually is by adding WordPress plugins.

However, if you are not familiar with coding, we strongly recommend you to do so, as changing the functions file might be trickier than it looks.

That is due to the nature of how WordPress and its updates work. Anytime, your theme will receive an update. If you modified your functions.php file, you are going to lose your changes. That means having to do all the work all over again.

When you update functions using WordPress plugins, you also better make sure your WordPress security is intact.

<!–[if lte IE 8]>
<![endif]–>Secure your page with Stage!
hbspt.cta.load(355484, ‘104906ab-9484-425b-b101-a6a478d876cb’, {});

Making coding errors in your functions file might lock you out of your website or even create vulnerabilities that hackers can use to access the system.

Changing your WordPress theme is another task that will be harder once you make changes in its PHP files.

After all, new themes come with their own functions.php file pre-loaded. Thus, a change in your theme’s file also means losing all customizations you made by using the functions.php file.

The functions file is created to behave like a plugin, adding features and functionalities to a website.

You can use it whenever there is no plugin to perform the feature you desire, or when a coder does not want to write less code than a fully functioning plugin would demand.

State of Marketing Report 2024

5 WordPress functions you need to learn right now

Now that you have a better understanding of WordPress functions, it is time to learn how to take advantage of PHP. Check out some of the modifications you can do by using this coding language and the functions.php file.

1. Add Google Fonts to your WordPress

Google Fonts are a great way to customize your website. It implements different fonts in your WordPress installation. It can help you reproduce your company’s branding, as used on other marketing materials.

There are a few plugins you can use to customize the fonts of your website, but you can also do so by editing your theme’s functions.php file.

You first need to visit the Google Fonts website, where you can find various fonts — as well as their weights — that you need to customize your website. Select those you are interested in and add them to your cart.

Then, click on the “Embed” tab and copy the href value. That address shows where your font is and the weights you selected when visiting Google Fonts.

Make sure you also take note of the CSS rules that apply to your font family. You will need to update them for the fonts to work on your website.

Source: Laborator

Now, all you have to do is visit your theme’s function.php page and add the following code, replacing the href with your font’s href.

<?php
function google_fonts() {
    wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap', false );
}
add_action( 'wp_enqueue_scripts', 'google_fonts' );

Having done that, add to your CSS the rules defined by Google Fonts. They will look something like this:

font-family: ‘Open Sans’, sans-serif;

Save changes, and you are all set to use the Google Font of your choosing.

2. Remove scripts from header to footer

Sometimes, when you buy a WordPress theme, some styles, scripts, and other complements come pre-installed, but they might not be useful to your site.

These complements can make your website load slower, which in turn can affect your SEO efforts negatively.

One option is to remove all the scripts from header to footer with a simple WordPress function. To do that, all you will need is to dequeue some extra WordPress JavaScripts on the parent theme.

You can also do that by using a plugin, although a function works as well. Just add this into the page template:

/**
 * Dequeue the Parent Theme scripts.
 *
 * Hooked to the wp_print_scripts action, with a late priority (100),
 * so that it is after the script was enqueued.
 */
function my_site_WI_dequeue_script() {
    wp_dequeue_script( 'comment-reply' ); //If you're using disqus, etc.
    wp_dequeue_script( 'jquery_ui' ); //jQuery UI, no thanks!
    wp_dequeue_script( 'fancybox' ); //Nah, I use FooBox
    wp_dequeue_script( 'wait_for_images' );
    wp_dequeue_script( 'jquery_easing' );
    wp_dequeue_script( 'swipe' );
    wp_dequeue_script( 'waypoints' );
}

add_action( 'wp_print_scripts', 'my_site_WI_dequeue_script', 100 );

/**
 * Dequeue the Parent Theme styles.
 *
 * Hooked to the wp_enqueue_scripts action, with a late priority (100),
 * so that it runs after the parent style was enqueued.
 */

function give_dequeue_plugin_css() {
    wp_dequeue_style('additional-parent-style');
    wp_deregister_style('additional-parent-style');
}
add_action('wp_enqueue_scripts','give_dequeue_plugin_css', 100);

3. Disable “continue reading” for your WordPress blog posts

Many templates use the “Continue reading” feature to make sure your blog posts will not crowd a page. But, sometimes, you do not want that to appear on your website.

To remove it using the functions.php file, all you need to do is add the following code in your theme, replacing “twentyeleven” with your theme file name:

function twentyeleven_continue_reading_link() {
    return ' <a href="'. esc_url( get_permalink() ) . '">' . __( '[...]', 'twentyeleven' ) . '</a>';
}
endif;

function twentyeleven_auto_excerpt_more( $more ) {
    return '' . twentyeleven_continue_reading_link();
}
add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );

4. Pull all metadata from a post with a function

Sometimes, you will need the metadata of your website for a specific post or page. That is much harder to do with a plugin, compared to a simple change in your functions.

So, if you need to obtain metadata from your posts, add the following code to your theme, replacing post_id with your unique post ID:

get_post_meta( int $post_id, string $key = ‘’, bool $single = false )

5. Detect when the reader is in a mobile device

Most of the time, if your user is viewing your website from a mobile device, they will face a couple of challenges if the page loads like it would on a computer.

To make sure the mobile version of your webpage is loading, a simple code snippet in your functions.php file should do the trick. Just add the following code to test if the current browser runs on a mobile device:

wp_is_mobile()

Changing the appearance of your site with these most commonly used WordPress functions does not mean you can’t use plugins on your website.

It just means that you will get a lighter installation, one that loads faster because most of its functions are already embedded in the functions.php file, which no WordPress can run without.

To make these changes, though, make sure to create a child theme from the original theme to place the changes in. Besides that, have a backup of your WordPress installation.

That will increase hosting security and guarantee you won’t lose your website if you make a mistake while uploading these changes.

Ready to start using these most important WordPress functions to make your site look more professional? Remember to check your code thoroughly before updating so you won’t run into any problems.

Are you still struggling to make your WordPress blog look the way you want? Download the free “WordPress Guide to Corporate Blogs” and learn how to master this CMS!

WordPress Guide for Corporate Blogs - Promotional Banner
Share
facebook
linkedin
twitter
mail

2024 State of Marketing Report

Your golden ticket to crush your goals with data-driven insights!

2024 State of Marketing Report

Your golden ticket to crush your goals with data-driven insights!

Subscribe to our blog

Sign up to receive Rock Content blog posts

Rock Content WriterAccess - Start a Free Trial

Order badass content with WriterAccess. Just as we do.

Find +15,000 skilled freelance writers, editors, content strategists, translators, designers and more for hire.

Want to receive more brilliant content like this for free?

Sign up to receive our content by email and be a member of the Rock Content Community!

Talk to an expert and enhance your company’s marketing results.

Rock Content offers solutions for producing high-quality content, increasing organic traffic, building interactive experiences, and improving conversions that will transform the outcomes of your company or agency. Let’s talk.