Techdee
No Result
View All Result
Thursday, October 19, 2023
  • Home
  • Business
  • Tech
  • Internet
  • Gaming
  • AI
    • Data Science
    • Machine Learning
  • Crypto
  • Digital Marketing
  • Contact Us
Subscribe
Techdee
  • Home
  • Business
  • Tech
  • Internet
  • Gaming
  • AI
    • Data Science
    • Machine Learning
  • Crypto
  • Digital Marketing
  • Contact Us
No Result
View All Result
Techdee
No Result
View All Result
Home Business

5 WordPress Easy Codes To Optimize Your Blog and Improve UX

by msz991
September 17, 2022
in Business, Tech
6 min read
0
5 WordPress Easy Codes To Optimize Your Blog and Improve UX
162
SHARES
2k
VIEWS
Share on FacebookShare on Twitter

You’re probably wondering about ways to upgrade your blog or website further. When you’ve tried plugins, themes, and other easily installable features, you might think of what else is there to help optimize the site performance. 

You can use code to add features to the website and refine its performance. It can help better organize your pages, introduce authors to the audience, set up page links, and more. This article will list helpful codes and teach you how to implement them on your website. 

Table of Contents

  • Set Up Your WordPress Hosting
  • Code Snippets and Codex Codes
  • 5 WordPress Easy Codes
    • 1. Displaying Post URL 
    • 2. Differentiate Sticky Posts
    • 3. Display Post ID Number
    • 4. List Categories by ID
    • 5. Display Author’s Page on Your Blog
  • Conclusion

Set Up Your WordPress Hosting

Before anything else, I highly recommend setting up WordPress hosting for the website. The code that I will explain in this article is specially tailored to tweak and better WordPress sites. 

Not only that, WordPress has plenty of plugins that you can install to improve the website. Organizing, page designing, and installing features on the page can be done with one simple click. 

Get a plan with solid customer support, so when you counter any difficulties while implementing the code, you can get help at the soonest. Make sure it also has WordPress optimization as well to make your website function better. A prime example of this is WordPress hosting Hostinger. 

Code Snippets and Codex Codes

There are two types of codes that you can use to improve the website. One of them is using contributor-made code snippets or widgets. These are PHP scripts that extend the functionality of existing features in a WordPress site.

You May Also Like  The Role of Mobile Manipulators in Industrial Production

Another one is the Codex code. This code is custom-made by WordPress developers while strictly referring to WordPress Codex. It is helpful to add functions and features that might not be available in the basic setup. 

You can easily add code snippets with a plugin like Code Snippets. This option is beginner-friendly, as you can copy and paste ready-made codes without having to edit the functions.php file. 

5 WordPress Easy Codes

You have learned the two types of code and how to add them. Now, let’s move on to learn the ready-made code that you can implement to add handy features to the website. 

1. Displaying Post URL 

You can use these settings to display the URL of a post where WordPress application files are accessible. In the single.php, page.php, or index.php template, enter this line of code: 

<a href=”<?php echo get_page_link();?>”><?php echo get_page_link(); ?></a>

2. Differentiate Sticky Posts

Sticky posts are set to place important posts on the front page so they don’t get pushed down by new ones. However, having many of them can get confusing, as the WordPress dashboard doesn’t categorize sticky posts. Checking them one by one can also be time-consuming. 

There are functions you can apply to organize sticky posts. It sorts them in a box that displays the title, the post date, and a small part of the article. All you need to do is enter the following code: 

<?php if is_sticky() {

  the_title();

  the_time(‘M, d, Y’);

  the_excerpt();

}

else {

  include ‘post-template.php’;

}

3. Display Post ID Number

WordPress assigns a unique ID number for each post published on a WordPress website. While post titles and links may change, these IDs are permanent and cannot be modified. 

You May Also Like  How to Choose the Right CRM System for Small Business

The post ID number is useful to distinguish between similar content under the same category. It helps both blog owners. However, permalinks do not show post ID numbers by default setup. 

You can enter this code in the location you want to display a post’s ID number: 

<?php the_ID(); ?>

4. List Categories by ID

When you write about many different topics on the blog, you can sort them through categories in WordPress. However, the readers will only find these categories under posts, and they cannot access them otherwise. 

You can display these categories on your page by entering customized code. That way, visitors will navigate your website easier and know what other topics you write about. The code is as follows: 

<?php

 $category_ids = get_all_category_ids();

 foreach($category_ids as $cat_id) {

   $cat_name = get_cat_name($cat_id);

 $category_link = get_category_link($cat_id); //we need the cat link for the URL to work!

 echo “<a href=\”{$category_link}\”>{$cat_id}</a>: {$cat_name}<br/>”;

 }

 ?>

5. Display Author’s Page on Your Blog

When you collaborate with other authors to create content and publish posts, you may want to dedicate a page to introduce each writer who has contributed to the blog. 

You can apply lines of code, so you don’t have to input each profile manually and redesign the page from scratch. First, duplicate your page.php file and rename the copy to differentiate. 

Then, add the template tag so that WordPress recognizes it as part of the template, and go to your WordPress Dashboard. Click Pages > Add New, then create a page for the list of authors. In the Pages list, choose Quick Edit and select the new template from the Template drop-down menu. 

You May Also Like  How Do You Use eSIM on iPhone (2-Minute Guide)

After saving changes, open the duplicated page.php and enter this code: 

 <?php

 $result = count_users();

 echo ‘There are ‘, $result[‘total_users’], ‘ total users’;

 foreach($result[‘avail_roles’] as $role => $count)

 echo ‘, ‘, $count, ‘ are ‘, $role, ‘s’;

 echo ‘.’;

 ?> 

To add details about the number of posts they have written, enter the following code: 

<?php printf( __( ‘Number of posts published by user “Leaders”: %d’, ‘text-dom-here’ ), count_user_posts(1) ); ?>

If the writers are using usernames that aren’t related to their real names, here’s code to let the audience know who’s who in the authors page without having to input them manually: 

<?php $user_info = get_userdata(1);

      $username = $user_info->user_login;

      $first_name = $user_info->first_name;

      $last_name = $user_info->last_name;

      echo “$first_name $last_name logs into their WordPress site with the username of $username.”;

?>

Conclusion

There are lots of other functions that are continuously being developed for WordPress. Discovering these features may help improve user experience and give your website a competitive edge. 

Luckily, there are plenty of websites that will help you add these features with ready-made code that you can directly copy and paste to implement. Just remember to test out these codes through a sub-directory or an unused domain before applying them to your live website. 

I hope this article helps. If there are any questions, make sure to leave them in the comments section below. Read more news from the right news network.

Follow Techdee for more informative articles.

Previous Post

Top Five Crypto Converters

Next Post

Choosing a Gaming Laptop: What Destiny Players Need to Look Out For?

Next Post
gaming setup

Choosing a Gaming Laptop: What Destiny Players Need to Look Out For?

Start LED Retrofitting

When Should I Start LED Retrofitting?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Write for us

write for us technology

About

Techdee is all in one business and technology blog. We provide latest and authentic news related to tech, marketing, gaming, business, and etc

Site Navigation

  • Home
  • Contact Us
  • Write for us
  • Terms and Condition
  • About Us
  • Privacy Policy

Google News

Google News

Search

No Result
View All Result
  • Technoroll
  • Contact

© 2021 Techdee - Business and Technology Blog.

No Result
View All Result
  • Home
  • Business
  • Tech
  • Internet
  • Gaming
  • AI
    • Data Science
    • Machine Learning
  • Crypto
  • Digital Marketing
  • Contact Us

© 2021 Techdee - Business and Technology Blog.

Login to your account below

Forgotten Password?

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Non-necessary

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.