EDITS.WS

Tag: wpcode

  • 42 Extremely Useful Tricks for the WordPress Functions File

    Are you wondering what you can do with the WordPress functions file?

    All WordPress themes come with a functions.php file. This file acts as a plugin, allowing theme developers and general users to add custom code in WordPress easily.

    In this article, we will show you some useful tricks for the WordPress functions file.

    Handy WordPress functions file tips and hacks

    What Is the Functions File in WordPress?

    The functions.php file is a WordPress theme file that comes with all free and premium WordPress themes.

    It acts as a plugin and allows theme developers to define theme features. Users can also use it to add their custom code snippets in WordPress.

    However, keeping custom code in your theme’s functions file is not the best way to save your customizations. If you update your theme, then the functions.php file will be overwritten, and you will lose your custom code snippets.

    Instead, we recommend everyone use WPCode, a free plugin that lets you insert code snippets into your WordPress website without editing any theme, plugin, or core WordPress files.

    The best part is that all your custom code is saved separately, so any WordPress updates won’t remove them.

    As a bonus, the WPCode plugin has an extensive library of pre-configured code snippets (including many on this list). You can deploy these code snippets with a few clicks.

    wpcode library

    Having said that, here is a list of items we will cover in this article. You can jump to one that interests you or simply follow along:

    How to Add These Code Snippets to Your Website

    Before we begin, let’s look at how to add the code snippets in this article to your WordPress functions file.

    1. Add Custom Code to Functions File Using WPCode (Recommended)

    First, you need to install and activate the WPCode plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

    Upon activation, go to Code Snippets » + Add Snippet page. You’ll see WPCode’s code library with many helpful custom code snippets already added.

    Add snippet

    If your code snippet does the same thing as of the snippets in the library, then you can try out the one already added there.

    Alternatively, click the ‘blank snippet’ link to continue adding your custom code snippet.

    On the next screen, provide a title for your custom code. This could be anything that helps you identify what this code snippet does.

    Adding your custom code

    Next, you need to choose the ‘Code Type’. If you are adding a code that works in the functions.php file, then you must select ‘PHP Snippet’.

    Below that, you need to copy and paste your custom code into the ‘Code Preview’ box.

    Finally, you need to set your snippet as ‘Active’ and click the ‘Save Snippet’ button.

    Activate and save

    Your saved snippet will now run like it would if you had added it to the functions.php file.

    You can repeat the process to add more snippets when needed. You can also deactivate a snippet without deleting it.

    2. Add Custom Code Directly to the Functions File

    The WPCode method is always better than adding code to the theme’s functions file.

    However, some users may be writing code for a client’s custom WordPress theme or simply prefer to add code to the functions.php file.

    In that case, here is how you can add code to your WordPress theme’s functions.php file.

    First, connect to your WordPress website using an FTP client. Once connected, navigate to the /wp-content/themes/your-wordpress-theme/ folder.

    Edit functions.php file

    There you will find the functions.php file. Simply right-click and select to edit or download the file to your computer for editing.

    You can edit it using any plain text editor like Notepad or TextEdit.

    Then, scroll down to the bottom of the functions.php file and paste your code snippet there. You can save your changes and upload the updated functions.php file to your theme folder.

    You can now visit your WordPress website to see your custom code in action.

    Now, let’s take a look at 42 different useful tricks for the WordPress functions file.

    1. Remove WordPress Version Number

    You should always use the latest version of WordPress. However, you may want to remove the WordPress version number from your site.

    Simply add this code snippet to your functions file or as a new WPCode snippet:

    function wpb_remove_version() {
    return '';
    }
    add_filter('the_generator', 'wpb_remove_version');
    

    For detailed instructions, see our guide on the right way to remove the WordPress version number.

    Want to white-label your WordPress admin area? Adding a custom dashboard logo is the first step in the process.

    First, you’ll need to upload your custom logo to your theme’s images folder as custom-logo.png. Your custom logo should be in a 1:1 ratio (a square image) in 16×16 pixels.

    After that, you can add this code to your theme’s functions file or as a new WPCode snippet:

    function wpb_custom_logo() {
    echo '
    <style type="text/css">
    #wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon:before {
    background-image: url(' . get_bloginfo('stylesheet_directory') . '/images/custom-logo.png) !important;
    background-position: 0 0;
    color:rgba(0, 0, 0, 0);
    }
    #wpadminbar #wp-admin-bar-wp-logo.hover > .ab-item .ab-icon {
    background-position: 0 0;
    }
    </style>
    ';
    }
    //hook into the administrative header output
    add_action('wp_before_admin_bar_render', 'wpb_custom_logo');
    

    For more details, see our guide on how to add a custom dashboard logo in WordPress.

    3. Change the Footer in WordPress Admin Panel

    The footer in the WordPress admin area shows the message ‘Thank you for creating with WordPress.’ You can change it to anything you want by adding this code:

    function remove_footer_admin () {
    
    echo 'Fueled by <a href="http://www.wordpress.org" target="_blank">WordPress</a> | WordPress Tutorials: <a href="https://www.wpbeginner.com" target="_blank">WPBeginner</a></p>';
    
    }
    
    add_filter('admin_footer_text', 'remove_footer_admin');
    

    Feel free to change the text and links that you want to add. Here is how it looks on our test site.

    Admin footer

    4. Add Custom Dashboard Widgets in WordPress

    You probably have seen the widgets that many plugins and themes add to the WordPress dashboard. You can add one yourself by pasting the following code:

    add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
    
    function my_custom_dashboard_widgets() {
    global $wp_meta_boxes;
    
    wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');
    }
    
    function custom_dashboard_help() {
    echo '<p>Welcome to Custom Blog Theme! Need help? Contact the developer <a href="mailto:yourusername@gmail.com">here</a>. For WordPress Tutorials visit: <a href="https://www.wpbeginner.com" target="_blank">WPBeginner</a></p>';
    }
    

    This is what it would look like:

    Custom dashboard widget

    For details, see our tutorial on how to add custom dashboard widgets in WordPress.

    5. Change the Default Gravatar in WordPress

    Have you seen the default mystery man avatar on blogs? You can easily replace it with your own branded custom avatar.

    Simply upload the image you want to use as the default avatar and add this code to your functions file or the WPCode plugin:

    function wpb_custom_default_gravatar( $avatar_defaults ) {
    	$myavatar = 'https://example.com/wp-content/uploads/2022/10/dummygravatar.png';
    	$avatar_defaults[$myavatar] = 'Default Gravatar';
    	return $avatar_defaults;
    }
    add_filter( 'avatar_defaults', 'wpb_custom_default_gravatar' );
    

    Now you can head to the Settings » Discussion page and select your default avatar.

    Custom default gravatar

    For detailed instructions, see our guide on changing the default gravatar in WordPress.

    6. Dynamic Copyright Date in WordPress Footer

    You can simply add a copyright date by editing the footer template in your theme. However, it will not show when your site started, and it will not automatically change the following year.

    This code can add a dynamic copyright date in the WordPress footer:

    function wpb_copyright() {
    global $wpdb;
    $copyright_dates = $wpdb->get_results("
    SELECT
    YEAR(min(post_date_gmt)) AS firstdate,
    YEAR(max(post_date_gmt)) AS lastdate
    FROM
    $wpdb->posts
    WHERE
    post_status = 'publish'
    ");
    $output = '';
    if($copyright_dates) {
    $copyright = "© " . $copyright_dates[0]->firstdate;
    if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
    $copyright .= '-' . $copyright_dates[0]->lastdate;
    }
    $output = $copyright;
    }
    return $output;
    }
    

    After adding this function, you’ll need to open your footer.php file and add the following code where you would like to display the dynamic copyright date:

    <?php echo wpb_copyright(); ?>
    

    This function looks for the date of your first post and the date of your last post. It then returns the years wherever you call the function.

    Tip: If you are using the WPCode plugin, then you can combine the two code snippets. After that, choose the ‘Site Wide Footer’ location in the ‘Insertion’ section of the snippet settings. This will automatically display the copyright date in the footer without editing your theme’s footer.php file.

    Add to footer using WPCode

    For more details, see our guide on how to add dynamic copyright dates in WordPress.

    7. Randomly Change the Background Color in WordPress

    Do you want to randomly change the background color on your WordPress blog for each visit and page reload? Here is how to easily do this.

    First, add this code to your theme’s functions file or the WPCode plugin:

    function wpb_bg() {
    $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
    $color ='#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].
    $rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
    
    echo $color; 
    } 
    

    Next, you’ll need to edit the header.php file in your theme. Find the <body> tag and add replace it with this line:

    <body <?php body_class(); ?> style="background-color:<?php wpb_bg();?>">
    

    You can now save your changes and visit your website to see this code in action.

    Random background colors

    For more details and alternate methods, see our tutorial on randomly changing the background color in WordPress.

    8. Update WordPress URLs

    If your WordPress login page keeps refreshing or you cannot access the admin area, then you need to update WordPress URLs.

    One way to do this is by using the wp-config.php file. However, if you do that, then you cannot set the correct address on the settings page. The WordPress URL and Site URL fields will be locked and uneditable.

    Instead, just add this code to your functions file to fix this:

    update_option( 'siteurl', 'https://example.com' );
    update_option( 'home', 'https://example.com' );
    

    Don’t forget to replace example.com with your domain name.

    Once logged in, you can go to the Settings page in the WordPress admin area and set the URLs.

    After that, you should remove the code you added to the functions file or WPCode. Otherwise, it will keep updating those URLs whenever your site is accessed.

    9. Add Additional Image Sizes in WordPress

    WordPress automatically generates several image sizes when you upload an image. You can also create additional image sizes to use in your theme.

    Simply add this code to your theme’s functions file or as a WPCode snippet:

    add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Mode
    add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Mode
    add_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode
    

    This code creates three new image sizes of different sizes. Feel free to tweak the code to meet your requirements.

    You can then display an image size anywhere in your theme using this code:

    <?php the_post_thumbnail( 'homepage-thumb' ); ?>
    

    For detailed instructions, see our guide on creating additional image sizes in WordPress.

    10. Add New Navigation Menus to Your Theme

    WordPress allows theme developers to define navigation menus and then display them.

    You can add this code to your theme’s functions file or as a new WPCode snippet to define a new menu location in your theme:

    function wpb_custom_new_menu() {
      register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
    }
    add_action( 'init', 'wpb_custom_new_menu' );
    

    You can now go to Appearance » Menus in your WordPress dashboard and see ‘My Custom Menu’ as the theme location option.

    Custom menu location

    Note: This code will also work with block themes with the full site editing feature. Adding it will enable the Menus screen under Appearance.

    Now you need to add this code to your theme where you want to display the navigation menu:

     <?php
    wp_nav_menu( array( 
        'theme_location' => 'my-custom-menu', 
        'container_class' => 'custom-menu-class' ) ); 
    ?>
    

    For detailed instructions, see our guide on how to add custom navigation menus in WordPress themes.

    11. Add Author Profile Fields

    Do you want to add extra fields to your author profiles in WordPress? You can easily do that by adding this code to your functions file or as a new WPCode snippet:

    function wpb_new_contactmethods( $contactmethods ) {
    // Add Twitter
    $contactmethods['twitter'] = 'Twitter';
    //add Facebook
    $contactmethods['facebook'] = 'Facebook';
    
    return $contactmethods;
    }
    add_filter('user_contactmethods','wpb_new_contactmethods',10,1);
    

    This code will add Twitter and Facebook fields to user profiles in WordPress.

    New profile fields

    You can now display these fields in your author template like this:

    <?php echo get_the_author_meta('twitter') ?>
    

    You may also want to see our guide on adding additional user profile fields in WordPress registration.

    12. Adding Widget-Ready Areas or Sidebars in WordPress Themes

    This is one of the most used code snippets, and many developers already know about adding widget-ready areas or sidebars to WordPress themes. But it deserves to be on this list for those people who don’t know.

    You can paste the following code in your functions.php file or as a new WPCode snippet:

    // Register Sidebars
    function custom_sidebars() {
    
    	$args = array(
    		'id'            => 'custom_sidebar',
    		'name'          => __( 'Custom Widget Area', 'text_domain' ),
    		'description'   => __( 'A custom widget area', 'text_domain' ),
    		'before_title'  => '<h3 class="widget-title">',
    		'after_title'   => '</h3>',
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    	);
    	register_sidebar( $args );
    
    }
    add_action( 'widgets_init', 'custom_sidebars' );
    

    Note: This code will also work with block themes with the full site editing feature. Adding it will enable the Widgets screen under Appearance.

    You can now visit the Appearance » Widgets page and see your new custom widget area.

    Custom widget area

    To display this sidebar or widget-ready area on your website, you’ll need to add the following code in the template where you want to display it:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('custom_sidebar') ) : ?>
    <!–Default sidebar info goes here–>
    <?php endif; ?>
    

    For more details, see our guide on how to add dynamic widget-ready areas and sidebars in WordPress.

    13. Manipulate the RSS Feed Footer

    Have you seen blogs that add their advertisements in their RSS feeds below each post? You can accomplish this easily with a simple function. Just paste the following code:

    function wpbeginner_postrss($content) {
    if(is_feed()){
    $content = 'This post was written by Syed Balkhi '.$content.'Check out WPBeginner';
    }
    return $content;
    }
    add_filter('the_excerpt_rss', 'wpbeginner_postrss');
    add_filter('the_content', 'wpbeginner_postrss');
    

    For more information, see our guide on how to add content and completely manipulate your RSS feeds.

    14. Add Featured Images to RSS Feeds

    The post thumbnail or featured images are usually only displayed within your site design. You can easily extend that functionality to your RSS feed with the following code:

    function rss_post_thumbnail($content) {
    global $post;
    if(has_post_thumbnail($post->ID)) {
    $content = '<p>' . get_the_post_thumbnail($post->ID) .
    '</p>' . get_the_content();
    }
    return $content;
    }
    add_filter('the_excerpt_rss', 'rss_post_thumbnail');
    add_filter('the_content_feed', 'rss_post_thumbnail');
    

    For more details, see our guide on how to add post thumbnails to your WordPress RSS feed.

    15. Hide Login Errors in WordPress

    Hackers can use login errors to guess whether they entered the wrong username or password. By hiding login errors in WordPress, you can make your login area and WordPress website more secure.

    Simply add the following code to your theme’s functions file or as a new WPCode snippet:

    function no_wordpress_errors(){
      return 'Something is wrong!';
    }
    add_filter( 'login_errors', 'no_wordpress_errors' );
    

    Now, users will see a generic message when they enter an incorrect username or password.

    Custom login errors

    For more information, see our tutorial on disabling login hints in WordPress error messages.

    16. Disable Login by Email in WordPress

    WordPress allows users to log in with their username or email address. You can easily disable login by email in WordPress by adding this code to your functions file or as a new WPCode snippet:

    remove_filter( 'authenticate', 'wp_authenticate_email_password', 20 );
    

    For more information, see our guide on how to disable login by email feature in WordPress.

    17. Disable Search Feature in WordPress

    If you want to disable your WordPress site’s search feature, simply add this code to your functions file or in a new WPCode snippet:

    function wpb_filter_query( $query, $error = true ) {
    if ( is_search() ) {
    $query->is_search = false;
    $query->query_vars[s] = false;
    $query->query[s] = false;
    if ( $error == true )
    $query->is_404 = true;
    }}
    

    This code simply disables the search query by modifying it and returning a 404 error instead of search results.

    For more information, see our tutorial on disabling the WordPress search feature.

    Pro Tip: Instead of giving up on WordPress search, we recommend trying out SearchWP. It is the best WordPress search plugin on the market that allows you to add a powerful and customizable search feature to your website.

    18. Delay Posts in RSS Feed

    Sometimes you may publish an article with a grammatical error or spelling mistake.

    The mistake goes live and is distributed to your RSS feed subscribers. If you have email subscriptions on your WordPress blog, then those subscribers will also get a notification.

    Simply add this code to your theme’s functions file or as a new WPCode snippet to delay posts in your RSS feed:

    function publish_later_on_feed($where) {
    
    	global $wpdb;
    
    	if ( is_feed() ) {
    		// timestamp in WP-format
    		$now = gmdate('Y-m-d H:i:s');
    
    		// value for wait; + device
    		$wait = '10'; // integer
    
    		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
    		$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR
    
    		// add SQL-sytax to default $where
    		$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
    	}
    	return $where;
    }
    
    add_filter('posts_where', 'publish_later_on_feed');
    

    In this code, we used 10 minutes as $wait or delay time. Feel free to change this to any number of minutes you want.

    For a plugin method and more information, see our detailed guide on how to delay posts from appearing in the WordPress RSS feed.

    19. Change Read More Text for Excerpts in WordPress

    Do you want to change the text that appears after the excerpt in your posts? Simply add this code to your theme’s functions file or as a new WPCode snippet:

    function modify_read_more_link() {
        return '<a class="more-link" href="' . get_permalink() . '">Your Read More Link Text</a>';
    }
    add_filter( 'the_content_more_link', 'modify_read_more_link' );
    

    20. Disable RSS Feeds in WordPress

    Not all websites need RSS feeds. If you want to disable RSS feeds on your WordPress site, then add this code to your theme’s functions file or as a new WPCode snippet:

    function new_excerpt_more($more) {
     global $post;
     return '<a class="moretag" 
     href="'. get_permalink($post->ID) . '">Your Read More Link Text</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    

    For a plugin method and more information, see our guide on how to disable RSS feeds in WordPress.

    21. Change Excerpt Length in WordPress

    WordPress limits excerpt lengths to 55 words. You can add this code to your functions file or as a new WPCode snippet if you need to change that:

    function new_excerpt_length($length) {
    return 100;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    

    Just change 100 to the number of words you want to show in the excerpts.

    For alternate methods, you may want to look at our guide on how to customize WordPress excerpts (no coding required).

    22. Add an Admin User in WordPress

    If you have forgotten your WordPress password and email, then you can add an admin user by adding this code to your theme’s functions file using an FTP client:

    function wpb_admin_account(){
    $user = 'Username';
    $pass = 'Password';
    $email = 'email@domain.com';
    if ( !username_exists( $user )  && !email_exists( $email ) ) {
    $user_id = wp_create_user( $user, $pass, $email );
    $user = new WP_User( $user_id );
    $user->set_role( 'administrator' );
    } }
    add_action('init','wpb_admin_account');
    

    Don’t forget to fill in the username, password, and email fields.

    Important: Once you log in to your WordPress site, don’t forget to delete the code from your functions file.

    For more on this topic, take a look at our tutorial on how to add an admin user in WordPress using FTP.

    23. Disable Language Switcher on Login Page

    If you run a multilingual website, then WordPress displays a language selector on the login page. You can easily disable it by adding the following code to your functions.php file or as a new WPCode snippet:

    add_filter( 'login_display_language_dropdown', '__return_false' );
    

    24. Show the Total Number of Registered Users in WordPress

    Do you want to show the total number of registered users on your WordPress site? Simply add this code to your theme’s functions file or as a new WPCode snippet:

    function wpb_user_count() {
    $usercount = count_users();
    $result = $usercount['total_users'];
    return $result;
    }
    // Creating a shortcode to display user count
    add_shortcode('user_count', 'wpb_user_count');
    

    This code creates a shortcode that allows you to display the total number of registered users on your site.

    Now you just need to add the shortcode [user_count] to your post or page where you want to show the total number of users.

    For more information and a plugin method, see our tutorial on how to display the total number of registered users in WordPress.

    25. Exclude Specific Categories From RSS Feed

    Do you want to exclude specific categories from your WordPress RSS feed? You can add this code to your theme’s functions file or as a new WPCode snippet:

    function exclude_category($query) {
    	if ( $query->is_feed ) {
    		$query->set('cat', '-5, -2, -3');
    	}
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');
    

    26. Disable URL Links in WordPress Comments

    By default, WordPress converts a URL into a clickable link in comments.

    You can stop this by adding the following code to your functions file or as a new WPCode snippet:

    remove_filter( 'comment_text', 'make_clickable', 9 );
    

    For details, see our article on how to disable autolinking in WordPress comments.

    27. Add Odd and Even CSS Classes to WordPress Posts

    You may have seen WordPress themes using an odd or even class for WordPress comments. It helps users visualize where one comment ends and the next one begins.

    You can use the same technique for your WordPress posts. It looks aesthetically pleasing and helps users quickly scan pages with lots of content.

    Simply add this code to your theme’s functions file:

    function oddeven_post_class ( $classes ) {
       global $current_class;
       $classes[] = $current_class;
       $current_class = ($current_class == 'odd') ? 'even' : 'odd';
       return $classes;
    }
    add_filter ( 'post_class' , 'oddeven_post_class' );
    global $current_class;
    $current_class = 'odd';
    

    This code simply adds an odd or even class to WordPress posts. You can now add custom CSS to style them differently.

    Here is some sample code to help you get started:

    .even {
    background:#f0f8ff;
    }
    .odd {
     background:#f4f4fb;
    }
    

    The end result will look something like this:

    Alternating background colors

    Need more detailed instructions? Take a look at our tutorial on how to add odd/even classes to your posts in WordPress themes.

    28. Add Additional File Types to Be Uploaded in WordPress

    By default, WordPress allows you to upload a limited number of the most commonly used file types. However, you can extend it to allow other file types.

    Just add this code to your theme’s functions file:

    function my_myme_types($mime_types){
        $mime_types['svg'] = 'image/svg+xml'; //Adding svg extension
        $mime_types['psd'] = 'image/vnd.adobe.photoshop'; //Adding photoshop files
        return $mime_types;
    }
    add_filter('upload_mimes', 'my_myme_types', 1, 1);
    

    This code allows you to upload SVG and PSD files to WordPress.

    You will need to find the mime types for the file types you want to allow and then use them in the code.

    For more on this topic, check out our tutorial on how to add additional file types to be uploaded in WordPress.

    WordPress uses a non-existent email address (wordpress@yourdomain.com) to send outgoing emails by default.

    This email address could be flagged as spam by email service providers.

    Using the WP Mail SMTP plugin is the proper way to fix this.

    WP Mail SMTP

    It fixes email deliverability issues and allows you to choose an actual email address to send your WordPress emails.

    To learn more, see our guide on how to fix WordPress not sending email issue.

    On the other hand, if you want to quickly change this to a real email address, then you can add the following code in your functions file or as a new WPCode snippet:

    // Function to change email address
    function wpb_sender_email( $original_email_address ) {
        return 'tim.smith@example.com';
    }
     
    // Function to change sender name
    function wpb_sender_name( $original_email_from ) {
        return 'Tim Smith';
    }
     
    // Hooking up our functions to WordPress filters 
    add_filter( 'wp_mail_from', 'wpb_sender_email' );
    add_filter( 'wp_mail_from_name', 'wpb_sender_name' );
    

    Don’t forget to replace the email address and name with your own information.

    The problem with this method is that WordPress is still using the mail() function to send emails, and such emails are most likely to end up in spam.

    For better alternatives, see our tutorial on how to change the sender name in outgoing WordPress emails.

    30. Add an Author Info Box in WordPress Posts

    If you run a multi-author site and want to showcase author bios at the end of your posts, then you can try this method.

    Start by adding this code to your functions file or as a new WPCode snippet:

    function wpb_author_info_box( $content ) {
    
    global $post;
    
    // Detect if it is a single post with a post author
    if ( is_single() && isset( $post->post_author ) ) {
    
    // Get author's display name
    $display_name = get_the_author_meta( 'display_name', $post->post_author );
    
    // If display name is not available then use nickname as display name
    if ( empty( $display_name ) )
    $display_name = get_the_author_meta( 'nickname', $post->post_author );
    
    // Get author's biographical information or description
    $user_description = get_the_author_meta( 'user_description', $post->post_author );
    
    // Get author's website URL
    $user_website = get_the_author_meta('url', $post->post_author);
    
    // Get link to the author archive page
    $user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author));
    	
    // Get User Gravatar
    $user_gravatar =  get_avatar( get_the_author_meta( 'ID' , $post->post_author) , 90 );
    
    if ( ! empty( $display_name ) )
    
    $author_details = '<p class="author_name">About ' . $display_name . '</p>';
    
    if ( ! empty( $user_description ) )
    // Author avatar and bio will be displayed if author has filled in description. 
    
    $author_details .= '<p class="author_details">' . $user_gravatar . nl2br( $user_description ). '</p>';
    
    $author_details .= '<p class="author_links"><a href="'. $user_posts .'">View all posts by ' . $display_name . '</a>';  
    
    // Check if author has a website in their profile
    if ( ! empty( $user_website ) ) {
    
    // Display author website link
    $author_details .= ' | <a href="' . $user_website .'" target="_blank" rel="nofollow noopener">Website</a></p>';
    
    } else {
    // if there is no author website then just close the paragraph
    $author_details .= '</p>';
    }
    
    // Pass all this info to post content
    $content = $content . '<footer class="author_bio_section" >' . $author_details . '</footer>';
    }
    return $content;
    }
    
    // Add our function to the post content filter
    add_action( 'the_content', 'wpb_author_info_box' );
    
    // Allow HTML in author bio section
    remove_filter('pre_user_description', 'wp_filter_kses');
    

    Next, you will need to add some custom CSS to make it look better.

    You can use this sample CSS as a starting point:

    .author_bio_section{
    background: none repeat scroll 0 0 #F5F5F5;
    padding: 15px;
    border: 1px solid #ccc;
    }
    
    .author_name{
    font-size:16px;
    font-weight: bold;
    }
    
    .author_details img {
    border: 1px solid #D8D8D8;
    border-radius: 50%;
    float: left;
    margin: 0 10px 10px 0;
    }
    

    This is how your author box will look like:

    Author bio box

    For a plugin method and more detailed instructions, check out our article on how to add an author info box in WordPress posts.

    31. Disable XML-RPC in WordPress

    XML-RPC is a method that allows third-party apps to communicate with your WordPress site remotely. This could cause security issues and can be exploited by hackers.

    To turn off XML-RPC in WordPress, add the following code to your functions file or as a new WPCode snippet:

    add_filter('xmlrpc_enabled', '__return_false');
    

    You may want to read our article on how to disable XML-RPC in WordPress for more information.

    32. Automatically Link Featured Images to Posts

    If your WordPress theme does not automatically link featured images to full articles, then you can try this method.

    Simply add this code to your theme’s functions file or as a new WPCode snippet:

    function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {
    
    If (! is_singular()) { 
    
    $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
    return $html;
    
    } else { 
    
    return $html;
    
    }
    
    }
    add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );
    

    You may want to read our article on how to automatically link featured images to posts in WordPress.

    33. Disable Block Editor in WordPress

    WordPress uses a modern and intuitive editor for writing content and editing your website. This editor uses blocks for commonly-used content and layout elements, which is why it’s called the Block Editor.

    However, you may need to use the older Classic Editor in some use cases.

    The easiest way to disable the block editor is by using the Classic Editor plugin. However, if you don’t want to use a separate plugin, then just add the following code to your functions file or as a new WPCode snippet:

    add_filter('gutenberg_can_edit_post', '__return_false', 5);
    add_filter('use_block_editor_for_post', '__return_false', 5);
    

    For more details, see our tutorial on how to disable the Block Editor and use the Classic Editor.

    34. Disable Block Widgets in WordPress

    WordPress switched from classic widgets to block widgets in WordPress 5.8. The new block widgets are easier to use and give you more design control than classic widgets.

    However, some users may still want to use classic widgets. In that case, you can use the following code in your theme’s functions file or as a new WPCode snippet:

    add_filter( 'use_widgets_block_editor', '__return_false' );
    

    For more details, see our article on how to disable widget blocks (restore classic widgets).

    35. Display the Last Updated Date in WordPress

    When visitors view a post or page on your WordPress blog, your WordPress theme will show the date the post was published. This is fine for most blogs and static websites.

    However, WordPress is also used by websites where old articles are regularly updated. In these publications, displaying the date and time the post was last modified is essential.

    Last updated date

    You can show the last updated date using the following code in your theme’s functions file or as a new WPCode snippet:

    $u_time          = get_the_time( 'U' );
    $u_modified_time = get_the_modified_time( 'U' );
    // Only display modified date if 24hrs have passed since the post was published.
    if ( $u_modified_time >= $u_time + 86400 ) {
    
    	$updated_date = get_the_modified_time( 'F jS, Y' );
    	$updated_time = get_the_modified_time( 'h:i a' );
    
    	$updated = '<p class="last-updated">';
    
    	$updated .= sprintf(
    	// Translators: Placeholders get replaced with the date and time when the post was modified.
    		esc_html__( 'Last updated on %1$s at %2$s' ),
    		$updated_date,
    		$updated_time
    	);
    	$updated .= '</p>';
    
    	echo wp_kses_post( $updated );
    }
    

    For alternate methods and more details, see our guide on how to display the last updated date in WordPress.

    36. Use Lowercase Filenames for Uploads

    If you run a multi-author website, then authors may upload images with filenames in upper and lowercase.

    Adding the following code ensures that all filenames are in lowercase:

    add_filter( 'sanitize_file_name', 'mb_strtolower' );
    

    Note: The code will not change filenames for existing uploads. For alternate methods, see our tutorial on how to rename images and media files in WordPress.

    37. Disable WordPress Admin Bar on Frontend

    By default, WordPress displays the admin bar at the top when a logged-in user views your website.

    You can disable the admin bar for all users except site administrators. Simply add the following code to your functions file or as a new WPCode snippet:

    /* Disable WordPress Admin Bar for all users */
    add_filter( 'show_admin_bar', '__return_false' );
    

    For more details, see our guide on how to disable the WordPress admin bar for all users except administrators.

    38. Change Howdy Admin Text in Admin Area

    WordPress displays a ‘Howdy Admin’ greeting in the WordPress dashboard. ‘Admin’ is replaced by the logged-in user’s name.

    Howdy greeting

    You can change the default greeting to your own by adding the following code in your functions file or as a new WPCode snippet:

    function wpcode_snippet_replace_howdy( $wp_admin_bar ) {
    
    	// Edit the line below to set what you want the admin bar to display intead of "Howdy,".
    	$new_howdy = 'Welcome,';
    
    	$my_account = $wp_admin_bar->get_node( 'my-account' );
    	$wp_admin_bar->add_node(
    		array(
    			'id'    => 'my-account',
    			'title' => str_replace( 'Howdy,', $new_howdy, $my_account->title ),
    		)
    	);
    }
    
    add_filter( 'admin_bar_menu', 'wpcode_snippet_replace_howdy', 25 );
    

    For more details, see our article on changing the ‘Howdy Admin’ message in WordPress.

    39. Disable Code Editing in Block Editor

    The block editor allows you to switch to the Code Editor. This comes in handy if you need to add some HTML code manually.

    However, you may want to keep this feature limited to site administrators.

    You can add the following code to your functions file or as a WPCode snippet to achieve this:

    add_filter( 'block_editor_settings_all', function ( $settings ) {
    	
    	$settings['codeEditingEnabled'] = current_user_can( 'manage_options' );
    
    	return $settings;
    } );
    

    40. Disable Plugin / Theme File Editor

    WordPress comes with a built-in editor where you can edit plugin files. You can see it by going to the Plugins » Plugin File Editor page.

    Plugin file editor in WordPress

    Similarly, WordPress also includes a file editor for classic themes at Appearance » Theme File Editor.

    Note: If you use a block theme, then the theme file editor is not visible.

    Theme file editor

    We don’t recommend using these editors for making changes to your theme or plugin. A tiny mistake in code can make your website inaccessible to all users.

    To disable the plugin/theme editor, add the following code to your functions file or as a WPCode snippet:

    // Disable the Plugin and Theme Editor
    if ( ! defined( 'DISALLOW_FILE_EDIT' ) ) {
    	define( 'DISALLOW_FILE_EDIT', true );
    }
    

    For more details, see our tutorial on how to disable the plugin/theme editor in WordPress.

    41. Disable New User Notification Emails

    By default, WordPress sends an email notification when a new user joins your WordPress website.

    If you run a WordPress membership website or require users to signup, then you will get a notification each time a user joins your website.

    To turn off these notifications, you can add the following to your functions file or as a new WPCode snippet:

    function wpcode_send_new_user_notifications( $user_id, $notify = 'user' ) {
    	if ( empty( $notify ) || 'admin' === $notify ) {
    		return;
    	} elseif ( 'both' === $notify ) {
    		// Send new users the email but not the admin.
    		$notify = 'user';
    	}
    	wp_send_new_user_notifications( $user_id, $notify );
    }
    
    add_action(
    	'init',
    	function () {
    		// Disable default email notifications.
    		remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
    		remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications' );
    
    		// Replace with custom function that only sends to user.
    		add_action( 'register_new_user', 'wpcode_send_new_user_notifications' );
    		add_action( 'edit_user_created_user', 'wpcode_send_new_user_notifications', 10, 2 );
    	}
    );
    

    For more details, see our tutorial on how to disable new user email notifications in WordPress.

    42. Disable Automatic Update Email Notifications

    Occasionally, WordPress may automatically install security and maintenance updates or update a plugin with a critical vulnerability.

    It sends an automatic update email notification after each update. If you manage multiple WordPress websites, then you may get several such emails.

    You can add this code to your functions file or as a new WPCode snippet to turn off these email notifications:

    / Disable auto-update emails.
    add_filter( 'auto_core_update_send_email', '__return_false' );
    
    // Disable auto-update emails for plugins.
    add_filter( 'auto_plugin_update_send_email', '__return_false' );
    
    // Disable auto-update emails for themes.
    add_filter( 'auto_theme_update_send_email', '__return_false' );
    

    To learn more, see our article on how to disable automatic update emails in WordPress.

    We hope this article helped you learn some new useful tricks for the functions.php file in WordPress. You may also want to see our ultimate guide to boost WordPress speed and performance and our expert picks for the best code editors for Mac and Windows.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post 42 Extremely Useful Tricks for the WordPress Functions File first appeared on WPBeginner.

  • How to Display Any Number of Posts in a WordPress Loop

    Do you want to show multiple blog posts in a WordPress loop?

    Using the loop, WordPress processes each of the posts to be displayed on the current page. It formats them according to how they match specified criteria within the loop tags.

    In this article, we will show how to display any number of posts in a WordPress loop.

    How to display any number of posts in a WordPress loop

    What Is the WordPress Loop?

    The loop is used by WordPress to display each of your posts. It is PHP code that’s used in a WordPress theme to show a list of posts on a web page. It is an important part of WordPress code and is at the core of most queries.

    In a WordPress loop, there are different functions that run to display posts. However, developers can customize how each post is shown in the loop by changing the template tags.

    For example, the base tags in a loop will show the title, date, and content of the post in a loop. You can add custom tags and display additional information like the category, excerpt, custom fields, author name, and more.

    The WordPress loop also lets you control the number of blog posts that you show on each page. This can be helpful when designing an author’s template, as you can control the number of posts displayed in each loop.

    That being said, let’s see how to add any number of posts to a WordPress loop.

    Adding Any Number of Posts in a WordPress Loop

    Normally, you can set the number of posts to be displayed in the loop from your WordPress admin panel.

    Simply head to Settings » Reading from the WordPress dashboard. By default, WordPress will show 10 posts.

    Reading settings WordPress

    However, you can override that number by using a Super Loop, which will allow you to display any number of posts in that specific WordPress loop.

    This will allow you to customize the display settings of your pages, including author profiles, sidebars, and more.

    First, you will need to open a template file where you would like to place the posts and then simply add this loop:

    <?php
    // if everything is in place and ready, let's start the loop
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    	// to display 'n' number of posts, we need to execute the loop 'n' number of times
    	// so we define a numerical variable called '$count' and set its value to zero
    	// with each iteration of the loop, the value of '$count' will increase by one
    	// after the value of '$count' reaches the specified number, the loop will stop
    	// *USER: change the 'n' to the number of posts that you would like to display
    
    	<?php static $count = 0;
    	if ( $count == "n" ) {
    		break;
    	} else { ?>
    
    		// for CSS styling and layout purposes, we wrap the post content in a div
    		// we then display the entire post content via the 'the_content()' function
    		// *USER: change to '<?php the_excerpt(); ?>' to display post excerpts instead
    
    		<div class="post">
    			<?php the_title(); ?>
    			<?php the_content(); ?>
    		</div>
    
    		// here, we continue with the limiting of the number of displayed posts
    		// each iteration of the loop increases the value of '$count' by one
    		// the final two lines complete the loop and close the if statement
    
    		<?php $count ++;
    	} ?>
    <?php endwhile; ?>
    <?php endif; ?>
    

    Note: You will need to replace the value of ‘n‘ in the if ( $count == "n" ) part of the code and choose any number.

    An easy way to add this code to your WordPress website is by using the WPCode plugin. It is the best code snippet plugin for WordPress that helps you manage custom code.

    By using WPCode, you don’t have manually edit theme template files and risk breaking something. The plugin will automatically insert the code for you.

    First, you need to install and activate the free WPCode plugin. For more details, please see our guide on how to install a WordPress plugin.

    Upon activation, you can head to Code Snippets » + Add Snippet from your WordPress dashboard. Next, you need to select the ‘Add Your Custom Code (New Snippet)’ option.

    Add new snippet

    After that, simply paste the custom code for the WordPress loop that we showed you above into the ‘Code Preview’ area.

    You will also need to enter a name for your code and set the ‘Code Type’ to ‘PHP Snippet’.

    Add custom loop code to WPCode

    Next, you can scroll down to the ‘Insertion’ section and choose where you would like to run the code.

    By default, WPCode will run it everywhere on your WordPress website. However, you can change the location to a specific page or use a shortcode to insert the code.

    Edit insertion method for code

    For this tutorial, we will use the default ‘Auto Insert’ method.

    When you are done, don’t forget to click the toggle at the top to make the code ‘Active’ and then click the ‘Save’ button. WPCode will now deploy the code on your WordPress blog and display the specified number of posts in the WordPress loop.

    We hope this article helped you learn how to display any number of posts in a WordPress loop. You may also want to see our guide on how to exclude sticky posts from the loop in WordPress and our expert picks for the must-have WordPress plugins for business websites.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Display Any Number of Posts in a WordPress Loop first appeared on WPBeginner.

  • How to Easily Add Smart App Banners in WordPress

    Do you want to add smart app banners in WordPress?

    Smart banners are an easy way to promote your mobile app and get visitors to download it. If an iOS user already has your app, then the banner will encourage them to open the app for a better user experience.

    In this article, we will show you how to add smart app banners to WordPress.

    How to add smart app banners in WordPress (easy)

    Why Add Smart App Banners in WordPress?

    Many website owners create a companion mobile app where visitors can browse their content in a way that’s optimized for mobile.

    Since these apps are designed for mobile devices, they often provide a better user experience. You can also show reminders, personalized content, offers, updates, and more using mobile push notifications. All of this means more engagement, conversions, and sales.

    If you don’t already have a mobile app, then you can see our complete guide on how to convert a WordPress website into a mobile app.

    You can encourage iPhone and iPad users to download your mobile app using a smart app banner. This is a banner that appears at the top of the screen when an iOS user visits your site using the Safari browser.

    An example of a smart app banner on a WordPress website

    Visitors can click the banner to download your app from the App Store. If the visitor already has your app, then the banner will ask them to open the app instead. In this way, you can get more downloads and engagement.

    If the visitor is using a non-Apple device or a different web browser, then WordPress will hide the banner from them automatically.

    For example, the following image shows the same website in the Chrome mobile browser.

    A hidden smart app banner.

    With that being said, let’s see how you can add smart app banners in WordPress. Simply use the quick links below to jump straight to the method you want to use:

    Method 1: Using WPCode (Show a Smart App Banner Across WordPress)

    The easiest way to add smart app banners to your WordPress website is by using WPCode. This free plugin allows you to show the same banner on every page and post using one line of code.

    With that in mind, WPCode is the perfect choice if you want to promote a single iOS application. However, if you want to show different banners on different pages, then we recommend using method 2 instead.

    When adding custom code to WordPress, some guides will ask you to edit your site’s functions.php file. We don’t recommend this, as even a small typo or mistake could cause common WordPress errors or even make your site inaccessible.

    By using WPCode, you can add custom code to WordPress without any risks. You can also enable and disable code snippets with the click of a button.

    First, you need to install and activate the free WPCode plugin. For more instructions, please see our beginners’ guide on how to install a WordPress plugin.

    Upon activation, head over to Code Snippets » Add Snippet. Next, click the ‘Use Snippet’ button under the ‘Add Your Custom Code (New Snippet)’ option.

    Adding an iOS smart app banner to WordPress

    This will take you to the ‘Create Custom Snippet’ page, where you can type in a name for the code snippet. This is just for your reference, so you can use anything you want.

    After that, open the ‘Code Type’ dropdown and choose ‘HTML Snippet’.

    Creating an Apple app banner using WPCode

    For the next step, you will need to know your application’s ID.

    To get this information, open a new browser tab and head to the Apple Services Marketing Tools page. Here, type in the name of the application you want to promote and click on the ‘Search’ icon.

    The App Marketing Tools website

    To see all the iOS apps that match your search term, simply scroll to the ‘Apps’ section.

    Here, find the app you want to promote and give it a click.

    Getting the app ID for an iPhone or iPad iOS app

    At the bottom of the screen, you will see a ‘Content Link’.

    The app ID is the value between id and ?. You will need this information in the next step, so either leave this tab open or make a note of the app ID.

    An Apple App ID

    Now you have the app ID, switch back to the WordPress dashboard. You can now add the following snippet into the code editor, replacing the app ID with the information you got in the previous step:

    <meta name="apple-itunes-app" content="app-id=12345678">
    

    With that done, you must scroll to the ‘Insertion’ box. If it isn’t already selected, click on ‘Auto Insert’ and then select ‘Site Wide Header’ from the dropdown menu.

    Adding custom code to the WordPress theme header

    When you are ready, scroll to the top of the page and toggle the ‘Inactive’ switch to ‘Active’.

    Finally, just click the ‘Save Snippet’ button to store your changes.

    Publishing a smart app banner to WordPress

    Now, the smart app banner will appear on your WordPress website.

    How to Test the Smart App Banner Code in WordPress

    The best way to test the smart app banner is by visiting your website on an iOS device using the Safari mobile app. In fact, the smart app banner won’t even appear if you try to view the mobile version of your WordPress site from desktop.

    If you need to quickly check whether the code snippet is working, then one workaround is to use your browser’s Inspect tool. It allows you to see whether the <meta name> code has been inserted into your site’s <head>section, which suggests it’s working as expected.

    To do this, go to any page or post on your WordPress blog. Then, right-click anywhere on the page and select ‘Inspect’.

    The Google Chrome Inspect tool

    A new panel will open, showing all the site’s code.

    Simply find the <head> section and click on its arrow to expand.

    Apple app code in the WordPress header

    Now, look for the <meta name="apple-itunes-app"> code you added in the previous step.

    If you see this code, then the smart app banner should be appearing on iOS devices.

    Testing the Apple smart app banner code

    Method 2: Using Smart App Banner (Add Banners to Specific Pages and Posts)

    Sometimes, you may want to only promote apps on specific pages and posts. For example, you typically won’t show a smart app banner on sales pages and landing pages as the banner might distract from the main call to action.

    You may even want to show different banners on different parts of your website. For instance, if you are an affiliate marketer, then you might have a list of apps you want to promote.

    In this case, we recommend using the Smart App Banner plugin. This plugin allows you to show different banners on different pages and include affiliate data in those banners. These features make it a great plugin for affiliate marketers.

    First, you will need to install and activate the Smart App Banner plugin. If you need help, then please see our guide on how to install a WordPress plugin.

    Upon activation, you can add an app banner to specific pages or posts, the WordPress homepage, or across your entire website.

    To start, let’s look at the app’s settings. Here, you can add a banner to every page and post or add a smart app banner to your homepage only.

    To start, go to Settings » Smart App Banner and type the application’s value into the ‘App ID’ field.

    Adding an app ID to a WordPress plugin

    You can get this information by following the same process described in Method 1.

    If you are using affiliate marketing to make money online blogging, then you can type your affiliate token into the ‘Affiliate data’ field. The information will vary, so you may need to log in to your affiliate portal or speak to your partners to get the right token.

    After that, you can either check the ‘Show on all pages’ box or leave it unchecked. If you leave the box unchecked, then the app banner will only appear on your homepage.

    Showing a smart app banner across your WordPress blog or website

    When you are happy with how the banner is set up, simply click on the ‘Save Changes’ button to make it live.

    Do you want to add a smart app banner to specific pages and posts instead? This allows you to control exactly where the banner appears on your website.

    For example, if you are an affiliate marketer, then you might promote different apps on different pages and then use Google Analytics to see which banners get the most conversions.

    To do this, simply open the page or post where you want to add the banner. Now, find the new ‘Smart App Banner’ section in the WordPress content editor.

    Adding a smart app banner to a WordPress page or post

    Here, just add the app ID and optional affiliate information by following the same process described above.

    When you are happy with the information you have entered, just click on ‘Update’ or ‘Publish’ to make your changes live.

    An example of a smart app banner on a WordPress blog or website

    Then, you can simply repeat these steps to add a smart app banner to more WordPress posts and pages.

    FAQs About Adding Smart App Banners in WordPress

    In this guide, we showed you how to promote your mobile app on specific posts and pages or across your entire WordPress website.

    If you still have questions, then here are our top FAQs about how to add smart banners to your WordPress website.

    What is a smart app banner?

    Smart app banners appear at the top of the Safari web browser and give users the option to open an app or download it from the Apple App Store.

    Since they are created by Apple, smart app banners have a consistent design that many iOS users recognize. They only appear to people who are using iPhones and iPads running iOS 6 or higher.

    Why can’t I see my smart app banner on desktop?

    The smart app banner won’t appear on desktop computers, even if you view the mobile version of your site.

    To see the banner in action, you will need to visit your site on an iPhone or iPad using the Safari mobile app.

    Why can’t I see the smart app banner on my iPhone or iPad?

    Smart app banners only appear on devices running iOS 6 or higher when you are using the Safari mobile app. If you don’t see the smart app banner, then you should start by checking you have the latest versions of both iOS and the Safari mobile app.

    The smart app banner also detects whether the device can support the app and if the app is available in your location. If you don’t see the smart app banner, then it’s possible that your device has failed one of these checks.

    Why has the smart app banner disappeared in Safari?

    If you dismiss the banner by clicking the ‘x’ button, then it won’t appear again by default.

    Depending on your mobile device, you may need to open a private browser tab, clear your cache or cookies, or perform some other action to reset your settings.

    We hope that this article helped you learn how to add smart app banners in WordPress. You may also want to see our guide on how to add web push notifications to your WordPress site or our expert picks for the best WordPress popup plugins.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Easily Add Smart App Banners in WordPress first appeared on WPBeginner.

  • How to Track Third-Party Domain Requests in WordPress

    Do you want to learn how to track third-party domain requests in WordPress?

    If your website is slow, then visitors may leave before it even has a chance to load. However, even if you’ve optimized every part of your website, third-party domain requests can still have a big impact on your page loading times.

    In this article, we will show you how to track third-party domain requests in WordPress.

    How to track third-party domain requests in WordPress

    Why Track Third-Party Domain Requests in WordPress?

    By reducing your page load times, you can improve the user experience, get more visitors, and boost your WordPress SEO. There are lots of ways to speed up your website, including optimizing your images and choosing the best WordPress hosting.

    However, third-party domain requests can also affect your site’s performance even with the best hosting and optimization.

    A third-party domain request loads content or resources from a location outside of your domain. Some common examples include content from social media sites like Twitter and Facebook, advertising networks including Google AdSense, and even some WordPress comment plugins.

    A large number of third-party domain requests can slow down your website. However, sometimes even a single third-party request can block the rest of the page from loading. When this happens, WordPress will connect to the third-party URL and download all the required content, before loading the rest of your page.

    With that being said, let’s see how you can speed up your website by tracking and optimizing third-party domain requests in WordPress.

    How to Identify Third-Party Domain Requests in WordPress

    The first step is identifying all the third-party domain requests your site is making, using Pingdom. Pingdom is a popular performance monitoring tool that allows you to monitor your WordPress server uptime. It can also show all your site’s third-party domain requests.

    First, you need to visit the Pingdom website and paste your domain name into the ‘URL’ field. Then, click on ‘Start Test.’

    Tracking third-party domain requests using Pingdom

    After a few moments, Pingdom will show a breakdown of your site’s performance. To see all the third-party domain requests, scroll to the ‘File Requests’ section.

    Here, you’ll see the content type, URL, and size of each request.

    Tracking third-party URL requests in WordPress using Pingdom

    To find the third-party requests, simply look for any items that don’t begin with your site’s domain name.

    If you want to learn more about a request, then simply hover your mouse over its bar in the waterfall chart.

    Analyzing domain requests using a waterfall chart and free online tool

    Here, you’ll see all the steps that WordPress takes to get content from this third-party domain including making a DNS lookup, SSL handshake, and downloading data from that domain.

    Pingdom also shows how long each step takes, so you can identify the domain requests that make the biggest impact on your site’s performance.

    If you don’t recognize a third-party service, then just paste its URL into a search engine such as Google. Often, this will bring up links to documentation, pages, and forums where you can learn more about the domain.

    Identifying and research external domain requests

    How to Optimize Third-Party Domain Requests

    Once you’ve identified the third-party domain requests that are hurting your website’s performance, there are a few different ways to optimize those requests and boost your WordPress speed.

    The method that works best for you may vary depending on how your WordPress website is set up, the requests it makes, and other factors. With that in mind, simply use the quick links below to jump straight to the method you want to learn more about.

    Method 1. Remove the Third-Party Domain Request

    This isn’t a good option for all WordPress blogs, but removing one or more third-party requests can have a huge impact on your page loading times.

    You may have added a domain request by accident, or you might have changed direction so a particular third-party request no longer works well for your business.

    For example, you may have originally added Google AdSense but now make more money selling WooCommerce products on your online store. By removing Google AdSense, you might improve your store’s performance to a point where you get lots more sales, and make far more money compared to showing online ads.

    Here, there’s no easy solution that will work for all websites. With that in mind, you may want to try removing different services and content from your site, and then tracking the impact this has on important metrics such as your conversion rates.

    If you do decide to remove feature and plugins that make third-party domain requests, then it’s smart to back up your WordPress website. This allows you to quickly restore your website if you encounter any errors, or simply realize you made a mistake.

    You may also want to put your site into maintenance mode while making this change, just in case it breaks your website.

    The steps for removing third-party domain requests will vary depending on the request.

    However, you can often find detailed step-by-step guides in the documentation for the related service, plugin, or software, or by typing your search query into Google. For more on this topic, please see our guide on how to properly ask for WordPress support and get it.

    Method 2. Remove Unnecessary WordPress Plugins

    Plugins are a huge reason why WordPress is so popular. With the right plugins, you can add missing features, extend the built-in functionality, and turn your WordPress blog into any kind of website.

    However, some WordPress plugins make a lot of third-party requests and may even slow down your website. You might be completely unaware that these requests are even happening.

    With that in mind, it’s a good idea to go to Plugins » Installed Plugins in the WordPress dashboard, and remove any plugins that you no longer need.

    A list of installed WordPress plugins, in the WordPress dashboard

    You can even try replacing multiple smaller plugins with a single WordPress plugin. For example, there are countless SEO plugins and tools on the market, but AIOSEO is a complete SEO toolkit that performs a long list of important SEO tasks.

    Method 3. Preconnect to Important Third-Party Domains

    Another option is to connect to the external domain right at the beginning of the page loading process. When a browser preconnects to an external domain first, it can often download the third-party content much faster.

    Just be aware that preconnecting to an external URL takes resources away from loading the rest of your page. If the external resource isn’t crucial, then prioritizing it in this way may hurt the user experience by delaying the rest of your content.

    To use the preconnect method, you’ll need a list of all your third-party domain requests. If you haven’t already, then you can get this information using Pingdom, and by following the process described above.

    After that, you’ll need to add custom code in WordPress. Some guides will tell you to edit your theme files directly, but this can cause many common WordPress errors. You also won’t be able to update your WordPress theme without losing customization.

    That’s why recommend WPCode.

    WPCode is the best code snippets plugin that allows you to add custom CSS, PHP, HTML, and more without putting your site at risk. You can also enable and disable your code snippets with the click of a button.

    First, you will need to install and activate the free WPCode plugin. For more information, see our step-by-step guide on how to install a WordPress plugin.

    Once the plugin is activated, go to Code Snippets » Add Snippet.

    How to add a custom snippet to WordPress using WPCode

    Here, you will see all the ready-made WPCode snippets you can add to your site. These include a snippet that allows you to completely disable comments, upload file types that WordPress doesn’t usually support, disable attachment pages, and much more.

    Simply hover your mouse over the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button when it appears.

    Adding custom JavaScript code to your website or blog

    On the next screen, you need to type in a title for the code snippet. This is just for your reference, so you can use anything you want.

    Then, open the ‘Code Type’ dropdown and choose ‘JavaScript Snippet.’

    Adding custom JavaScript to a WordPress website

    With that done, you’re ready to add each domain that WordPress should preconnect to.

    For example, in the following code snippet we’re preconnecting to Google Fonts.

    <link rel="preconnect" href="https://fonts.googleapis.com" crossorigin />
    

    In the code editor, simply add each external URL that you want to use.

    Preconnecting to a third-party domain

    With that done, go ahead and scroll to the ‘Insertion’ settings. Here, select ‘Auto Insert’ if it isn’t already selected.

    You can then open the ‘Location’ dropdown and choose ‘Site Wide Header.’

    Adding code to a WordPress header

    When you’re ready to make the code snippet live, scroll to the top of the page and click on the ‘Inactive’ toggle so it changes to ‘Active.

    Then, click on the ‘Save Snippet’ button.

    Optimizing third-party domain requests in WordPress

    Method 4. Implement DNS Prefetching

    DNS prefetching allows you to perform a DNS lookup in the background before the visitor needs the linked content or resource. This is particularly useful for third-party resources that are used across your website, such as Google Analytics, Google Fonts, or your WordPress Content Delivery Network (CDN) service.

    To use DNS prefetching, simply create a new JavaScript snippet using WPCode, and by following the same process described above.

    Adding DNS prefetching in WordPress

    With that done, add each domain name that you want to prefetch using the following format:

     <link rel="dns-prefetch" href="//fonts.googleapis.com">
    

    After entering this information, add the code to your site-wide header by following the steps described in Method 3, and then publish the code snippet.

    Method 5. Host Resources Locally

    When used correctly, preconnecting and prefetching allow you to make third-party domain requests without impacting the visitor experience. However, where ever possible you should try to host resources and content locally.

    Retrieving content from a local server is typically much faster, and it’s easier to improve that content’s performance. For example, you might use a caching plugin, or set up a CDN.

    There are lots of different WordPress plugins and services that can help you host content locally. For example, if you want to use custom typography then you can host local fonts in WordPress rather than loading them from a third-party such as Google Fonts.

    Similarly, you can easily add unique icon fonts to your WordPress theme using a plugin such as SeedProd.

    If you’re using Google Ads, Google Analytics, Campaign Manager, or other popular free Google products, then you can host the gtag.js script locally on your own server using MonsterInsights with the Performance Addon.

    By replacing external domain requests with local resources, you can often improve your website’s performance without compromising on its features and content.

    Method 6. Use Lazy Loading

    Instead of loading all your content at once, lazy loading downloads only the content visible on the user’s screen. It will then load more content as the user scrolls down the screen. This can make it seem like the page is loading faster.

    WordPress will lazy load images by default, but depending on their location it may help to lazy load externally hosted content too. For example, if you want to embed YouTube videos in WordPress blog posts, then you can choose a plugin that has lazy loading built-in.

    Other plugins such as Smash Balloon YouTube Feed come with built-in caching and delayed loading for the video player. This can improve the perceived page load times, even when you’re showing content from third-party websites.

    We hope this article helped you learn how to track third-party domain requests in WordPress. You may also want to check out our guide on how to create a custom Instagram photo feed, or see our expert pick of the best YouTube video gallery plugins for WordPress.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Track Third-Party Domain Requests in WordPress first appeared on WPBeginner.

  • How to Fix Custom Fields Not Showing in WordPress

    Are you unable to find the ‘Custom Fields’ option on your WordPress site?

    ‘Custom fields’ is an advanced WordPress feature that helps you add custom content and metadata to your WordPress posts and pages.

    In this article, we will show you how to quickly fix the custom fields not showing issue in WordPress.

    Fixing custom fields not showing in WordPress issue

    Fixing Custom Fields Not Showing Issue in WordPress

    Custom fields are typically associated with WordPress posts, pages, or custom post types.

    Often, you will find custom fields mentioned in various WordPress tutorials around the web. Still, you will likely not see the custom fields option on your site, especially if you recently started your WordPress blog.

    In the past, custom fields were visible by default on the post editing screen of all WordPress sites.

    However, the WordPress core development team decided to hide it by default for all new users since it is an advanced feature.

    They also made it easy for anyone to make the custom fields visible with just a few clicks from within the post editing screen.

    Simply create or edit an existing post/page, then click on the three-dot menu in the top right corner of the screen.

    Block editor preferences

    At the bottom of the menu, click on the ‘Preferences’ option.

    This will bring up the block editor ‘Preferences’ popup. From here, you need to switch to the ‘Panels’ tab and switch the toggle next to the ‘Custom Fields’ option.

    Show custom fields panel

    Note: If you don’t see the Custom Fields option on your site, then please scroll to the troubleshooting section below in this article.

    WordPress will then tell you that a page reload is required to enable Custom Fields.

    Simply click on the ‘Enable & Reload’ button to continue.

    The editor screen will then reload, after which you can scroll down to the bottom of the page and find the ‘Custom Fields’ box there.

    Custom Fileds meta box now visible

    WordPress remembers your display choice and will continue to display the custom fields box whenever you edit posts or pages on your WordPress website.

    You can now use the Custom Fields box to add, edit, and delete custom fields and their values.

    What Are Custom Fields? What Can You Do With Them?

    By default, when you write a new post, page, or any content type, WordPress saves it into two different areas. The first part is the body of your content that you add using the block editor.

    The second part is the information about that particular content. For example, title, author name, date/time, and more. This post information is called metadata.

    Apart from the default post metadata, WordPress also allows you to save custom metadata by using custom fields.

    To learn more, see our beginner’s guide to WordPress custom fields with examples, tips, and tricks you can use on your website.

    WordPress developers use custom fields to store custom post metadata for your posts. For example, the All in One SEO plugin uses custom fields to store SEO settings for your posts.

    AIOSEO custom fields

    However, plugin developers usually create custom meta boxes instead of using the default custom fields box. This makes it easier for users to input information.

    If you want to create a custom meta box to easily input custom metadata, then see our guide on adding custom meta boxes in WordPress.

    Troubleshooting Custom Fields in WordPress

    Recently one of our readers came to us with a problem where the Custom Fields option was missing from the block editor preferences. After some investigation, we were able to find the cause of the issue.

    If your WordPress site is missing the Custom Fields option under the ‘Preferences’ menu, then you need to check if you have the Advanced Custom Fields (ACF) plugin installed and activated on your website.

    ACF is a popular WordPress plugin that developers use to create custom meta boxes.

    In ACF version 5.5.13, they added a setting to remove the default WordPress custom field meta box. This speeds up the load times on the post editing page. The idea is that you shouldn’t need the default meta box since you are using ACF.

    However, if you want to enable the default WordPress custom field meta box, then you need to add the following code to your WordPress theme using the functions.php file or WPCode:

    add_filter('acf/settings/remove_wp_meta_box', '__return_false');
    

    For more details, please see our guide on how to easily add custom code in WordPress.

    We hope this article helped you fix the custom fields not showing issue on your WordPress site. You may also want to see our ultimate list of the most useful WordPress tips, tricks, and hacks and our expert picks for the must have WordPress plugins to grow your website.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Fix Custom Fields Not Showing in WordPress first appeared on WPBeginner.

  • How to Add Affiliate Disclosure for Each Blog Post Automatically

    Do you want to add an affiliate disclosure for each blog post automatically?

    Affiliate marketing is one of the easiest ways to make money online. However, if you don’t disclose your affiliate links then you could end up in legal trouble.

    In this article, we will show you how you can add an affiliate disclosure to all your WordPress blog posts.

    How to add affiliate disclosure for each blog post automatically

    Why Add an Affiliate Disclosure to Each WordPress Blog Post?

    With affiliate marketing, you earn a commission every time someone clicks a referral link and makes a purchase. It’s a great way to make money online blogging with WordPress.

    However, you must make it clear that your links are paid advertisements by adding an affiliate disclaimer. That just means posting a short notice explaining what affiliate marketing is, and that you get money from talking about the product or service.

    Many countries have laws about failing to disclose paid endorsements. For example in the United States, you might get a fine from the Federal Trade Commission. You may even end up banned from reputable networks such as Amazon affiliates.

    Even if you don’t get into legal trouble, customers who click on undisclosed affiliate links may feel tricked and stop visiting your WordPress website.

    How to Add an Affiliate Disclosure to Each WordPress Blog Post

    One option is to publish the affiliate disclaimer on its own page, as we do on WPBeginner.

    The WPBeginner affiliate disclaimer page

    You can then add a link to every page that features an affiliate URL. This may be a good choice if you have a longer disclosure and don’t want to distract from the post’s content.

    If yours is short, then you can often add the full text of the disclaimer to every post.

    An example affiliate disclaimer on a blog

    No matter which option you choose, you can save time and effort by adding the affiliate disclosure automatically. Simply use the quick links below to jump straight to the method you want to use.

    Pretty Links is one of the best affiliate marketing plugins that can automate all your affiliate activities, including adding a disclosure.

    Pretty Links comes with an advanced auto-linking feature that allows you to enter the keywords or phrases that you want to turn into affiliate URLs.

    Every time you type this word or phrase, Pretty Links will turn it into an affiliate URL automatically. Even better, if you have created a disclosure notice page, Pretty Links can also add a link to it in the post.

    For example, if you add “MacBook Pro” as a keyword and then use that phrase in a new post, then Pretty Links will automatically turn “MacBook Pro” into an affiliate URL and add a link to your disclosure notice page.

    An affiliate disclaimer, created using Pretty Links

    Note: Pretty Links won’t insert the disclosure link if you only add affiliate URLs manually. It only works when a post uses automatic keyword linking.

    To get started, you’ll need to install and activate Pretty Links. If you need help, then please see our guide on how to install a WordPress plugin.

    Upon activation, go to Pretty Links » Activate. You can then add your license key to the following field: ‘Enter Your Pretty Links Pro License Key.’

    Activating the Pretty Links WordPress plugin

    You can find this information under your account on the Pretty Links website. After typing in this information, click on the ‘Activate’ button.

    With that done, you’ll need to go to Pretty Links » Add New and then add the first link you want to manage using the Pretty Links plugin.

    For detailed step-by-step instructions, please see our guide on how to cloak affiliate links on your WordPress site.

    How to cloak an affiliate link in WordPress with Pretty Links

    After that, click on the ‘Pro’ tab. In the ‘Keywords’ field, type in each word or phrase where you want to automatically insert this affiliate URL.

    Simply repeat this process for all your affiliate links.

    Adding keywords to the Pretty Links affiliate linking plugin

    Every time it adds this affiliate URL, Pretty Links will also add a link to your disclosure notice.

    The next step is creating the disclosure notice page that Pretty Links will link to. Simply go to Pages » Add New. You can then type in your affiliate disclaimer and add any categories or tags that you want to use.

    An example affiliate disclaimer

    When you’re happy with your disclaimer, publish the page to make it live. It’s a good idea to make a note of the page’s URL, as you’ll need it in the next step.

    Once you’ve done that, simply go to Pretty Links » Options. Then, click on the ‘Replacements’ tab.

    Pretty Links' auto-linking and replacement settings

    Here, check the ‘Enable Replacements’ box if it isn’t already selected.

    After that, check the ‘Link to Disclosures’ box. In the ‘URL’ box, go ahead and enter your affiliate disclosure URL.

    Pretty Links Disclosure Notice

    By default, Pretty Links will use ‘Affiliate Link Disclosures’ as your link’s text. However, you can change this to anything you want by typing into the ‘Text’ field.

    You can also change where Pretty Links adds the affiliate disclaimer link. By default, it shows the URL at the bottom of the post, so it doesn’t distract visitors from the post’s content.

    Another option is to add the disclaimer to the top of the post. This is where we include it on WPBeginner.

    WPBeginner Disclosure Notice

    This lets visitors know the post contains an affiliate link before they start reading, which is a good way to build trust with your audience. However, some people may see the disclaimer and decide not to stay on the page, which can increase your bounce rate.

    You can also add the disclaimer to both the top and bottom of each post. This may be a good idea if you write very long posts, but most sites don’t need multiple disclosures per page.

    To place the affiliate URL, simply open the ‘Position’ dropdown and choose Bottom, Top, or Top and Bottom.

    Changing where an affiliate disclaimer appears on your WordPress website

    Once you’ve done that, just scroll to the bottom of the page.

    Then, click on the ‘Update’ button.

    Saving your Pretty Links settings

    Now, Pretty Links will add an affiliate disclosure link every time it auto-inserts an affiliate URL to your posts, pages, or custom post types.

    Method 2. Add Affiliate Disclosure Using WPCode (More Customizable)

    Sometimes you may want to add the affiliate disclosure to different areas of every blog post. For example, you might show the disclosure after you mention each affiliate product for the first time.

    In this case, you can create a shortcode that adds your affiliate disclaimer. This gives you complete control over where the disclosure appears, without you having to type the entire text every single time.

    A custom shortcode created with WPCode

    The easiest way to create a custom shortcode is using WPCode. This plugin lets you add code snippets to WordPress without editing your theme’s functions.php file.

    WPCode also helps you avoid common errors by performing smart code snippet validation.

    There are lots of ways to add an affiliate disclosure using WPCode. Besides the shortcode method, we’ll also share an easy way to automatically add the disclaimer to every post, page, or custom post type.

    The first thing you need to do is install and activate the free WPCode plugin on your website. For more details, see our step-by-step guide on how to install a WordPress plugin.

    Upon activation, go to Code Snippets » Add Snippet.

    Adding a custom code snippet to WordPress

    This will bring you to the ‘Add Snippet’ page where you can see all the ready-made snippets that you can use on your site.

    Since we want to add custom code in WordPress, hover your mouse over ‘Add Your Custom Code (New Snippet).’ Then, click on ‘Use snippet’ when it appears.

    Adding custom snippets to WordPress

    To start, enter a title for the custom code snippet.

    This could be anything that helps you identify the snippet in the WordPress admin area.

    Adding a title to a WPCode custom code snippet

    We’re going to add a PHP snippet, so open the ‘Code Type’ dropdown and choose the ‘PHP Snippet’ option.

    You can then go ahead and paste the following code into the code box:

    function disclosure() {
        return "<p class='disclosure'>This site may contain links to affiliate websites, and we receive an affiliate commission for any purchases made by you on the affiliate website using such links.</p>";
    }
    
    add_shortcode( 'disclosure', 'disclosure' );
    

    You can use any text as your affiliate disclaimer, simply by editing the code above. For example, you might want to add a link in HTML to your affiliate disclosure page.

    Once you’ve done that, scroll to the ‘Insertion’ section and make sure ‘Auto Insert’ is selected.

    Auto-inserting custom code snippets in WordPress

    Then, open the ‘Location’ dropdown and choose ‘Frontend Only’ since we only want to use this code on our site’s frontend, which is what visitors see when they visit your site.

    You can also organize your snippets by adding tags.

    When you’re happy with how the snippet is set up, scroll to the top of the screen and click on ‘Save Snippet.’

    Saving your WPCode snippet

    After that, you can make the code snippet live by clicking the ‘Active’ toggle.

    Finally, don’t forget to save the change by clicking on ‘Update.’

    Updating a custom code snippet in WordPress

    Now you can add the affiliate disclosure to any page, post, or custom post type using the [disclosure] shortcode. For more details on how to place the shortcode, you can see our guide on how to add a shortcode in WordPress.

    How to Automatically Display the Affiliate Disclosure with WPCode

    With WPCode, there are lots of different ways to add an affiliate disclosure to your WordPress website, including automatically adding it to every post.

    This can save you a lot of time and effort, since you don’t need to add the shortcode manually. However, the disclosure will appear in the same location on every page.

    To automatically add the disclaimer, simply create a new custom code snippet by following the same process described above. However, this time open the ‘Code Type’ dropdown and select ‘HTML Snippet.’

    Adding an HTML snippet to WordPress

    You can now add your disclaimer in the code editor, complete with the formatting that you want to use. For example, here we’re adding a simple disclaimer as a new paragraph:

    <p>This site may contain links to affiliate websites, and we receive an affiliate commission for any purchases made by you on the affiliate website using such links.</p>
    

    Next, scroll to the ‘Insertion’ section and open the ‘Location’ dropdown.

    You can now choose where this disclaimer should appear, such as ‘Insert After Post’ or ‘Insert Before Content.’

    Automatically inserting an affiliate disclaimer

    You can then go ahead and enable the snippet by following the same process described above. WPCode will now automatically show the disclaimer on every page, post, and custom post type, without you having to add the shortcode manually.

    Method 3. Add Affiliate Disclosure Using Full-Site Editor (Block-Enabled Themes Only)

    If you’re using a block-based theme like Hestia Pro, then you can add an affiliate disclosure to your theme’s blog post template.

    This is a good choice if you want to show the exact same disclosure on every blog post. However, you won’t have the option to change the style or text on individual posts, so it’s not a good choice if you want to show different information on different pages.

    To use this method, go to Themes » Editor in the WordPress dashboard.

    Opening the WordPress full-site editor (FSE)

    By default, the full-site editor will show your theme’s home template, so you’ll typically want to select a new template.

    If you want to show the affiliate disclosure across your entire website, then we recommend adding it to the footer template part. 

    However, if you just want to show the disclaimer on your blog posts, then click on Templates on the left-hand side of the screen in the Design section.

    Adding an affiliate disclosure using the full-site editor (FSE)

    The editor will now show all the layouts that make up your WordPress theme.

    Simply click go ahead and click on ‘Single.’

    Adding an affiliate disclaimer to a WordPress blog post template

    WordPress will now show a preview of the template.

    To edit this template, go ahead and click on the small pencil icon.

    Editing a blog post template in a block-enabled WordPress theme

    With that done, click on the blue ‘+’ icon in the top left corner.

    In the search bar that appears, type in ‘Paragraph’ to find the right block. 

    Adding a Paragraph block to a full-site template

    You can now drag and drop the block onto the area where you want to show the disclaimer. 

    Now, click on the block and type in your affiliate disclaimer. 

    Adding text to a WordPress blog template

    You may also want to change how the disclaimer looks. 

    To change the font size, background color, and more, simply click to select the paragraph block. Then, select the ‘Block’ tab in the right-hand menu.

    Styling affiliate disclaimers using the WordPress FSE block-based editor

    You can now change the background color and text color, or make the disclaimer bigger or smaller using the settings in the right-hand menu.

    When you’re happy with how the disclaimer looks, click on the ‘Save’ button.

    An example of an affiliate disclaimer, created using the FSE

    Now, if you visit any blog post on your affiliate website, you’ll see the disclaimer in action. 

    We hope this article helped you learn how to add affiliate disclosures for each blog post automatically. You can also go through our guide on the best giveaway and contest plugins and how to create an email newsletter the RIGHT way.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Add Affiliate Disclosure for Each Blog Post Automatically first appeared on WPBeginner.

  • WordPress Custom Fields 101: Tips, Tricks, and Hacks

    Are you looking to make the most of custom fields on your WordPress website?

    Custom fields are a handy WordPress feature that allows you to add extra data and information to your WordPress posts and pages. A lot of popular WordPress plugins and themes use custom fields to store important data.

    In this article, we will show you how to use WordPress custom fields with some tips, tricks, and hacks.

    WordPress custom fields 101 tips tricks and hacks

    Since this is a long article, we have added a table of contents for easier navigation. Just use the quick links below to jump to the section you want to read:

    What Are WordPress Custom Fields?

    WordPress custom fields are metadata used to add extra information to the post or page you are editing.

    By default, when you write a new post, page, or any other content type, WordPress saves that content in two different parts.

    The first part is the body of your content that you add using the WordPress content editor.

    The second part is the information about that content. For example, the title, author, date, time, and more. This information is called metadata.

    A WordPress website automatically adds all the required metadata to each post or page you create. You can also create and store your own metadata by using custom fields.

    By default, the custom fields option is hidden on the post edit screen. To view it, you need to click on the three-dot menu in the top-right corner of the screen and select ‘Preferences’ from the menu.

    Open preferences in content editor

    This will open a popup where you need to switch to the ‘Panels’ tab and then enable the ‘Custom fields’ option.

    After that, simply click on the ‘Enable & Reload’ button to reload the post editor.

    Enable custom fields option

    The post editor will reload, and you will be able to see the Custom Fields panel below the content editor.

    Custom fields can be used to add any information related to the post, page, or other content type. This meta information can then be displayed in your theme.

    View custom fields in WordPress

    However, to do that, you will need to edit your WordPress theme files.

    Note: This tutorial is recommended for users who are already familiar with editing theme files. It is also helpful for aspiring WordPress developers who want to learn how to properly use custom fields in their own themes or plugins.

    Having said that, let’s take a look at how to add and use custom fields in WordPress.

    Adding Custom Fields in WordPress

    First, you need to open a post or page in the block editor so that you can add custom fields. Then, you must go to the Custom Fields meta box.

    Adding custom field name and value

    Next, you need to provide a Name for your custom field and then enter its Value. Click on the ‘Add Custom Field’ button to save it.

    The field will be stored and displayed in the Custom Fields meta box like this:

    View newly created custom field

    You can edit this custom field any time you want and then just click on the ‘Update’ button to save your changes. You can also delete it if you don’t want to use it anymore.

    Now, you need to save your post to store your custom field settings.

    Displaying Custom Fields in WordPress Themes

    To display your custom field on your website, you will need to edit your WordPress theme files and code snippets.

    We don’t recommend directly editing the theme files because the slightest mistake can break your website. An easier way to do this is by using WPCode.

    It is the best code snippet plugin for WordPress that lets you add custom code and manage snippets from your WordPress dashboard.

    If you haven’t done this before, then we also recommend reading our guide on how to copy and paste code in WordPress.

    First, you will need to install and activate the free WPCode plugin. For more details, please see our beginner’s guide on how to install a WordPress plugin.

    Upon activation, you will need to go to Code Snippets » + Add Snippet from the WordPress dashboard and select the ‘Add Your Custom Code (New Snippet)’ option.

    Adding a code snippet to your WordPress website

    Now you need to copy this code to add to your theme files:

    <?php echo get_post_meta($post->ID, 'key', true); ?>
    

    Don’t forget to replace key with the name of your custom field.

    Next, you must enter the code into the ‘Code Preview’ area and change the Code Type to ‘PHP Snippet’.

    Enter custom fields code

    For example, we used this code in our demo theme:

    <p>Today's Mood: <?php echo get_post_meta($post->ID, 'Mood', true); ?></p>
    

    From here, you can scroll down to the Insertion section.

    Here, you can select where the code will run. By default, WPCode will Auto Insert the code and run it everywhere on your website.

    Edit insertion method for code

    However, you can change this and select where you would like the custom field to appear.

    For example, we will choose the ‘Page Specific’ tab and select the ‘Insert Before Post’ option. This way, the custom field will appear at the beginning of the blog post.

    Insert before post

    You can now save your changes and visit the post where you added the custom field to see it in action.

    You can use this custom field in all your other WordPress blog posts as well.

    Displaying custom field

    You can also easily adjust the custom field for different blog posts. Simply create a new post or edit an existing one.

    Then, go to the Custom Fields meta box and select your custom field from the dropdown menu and enter its Value.

    Reuse custom field

    Once you are done, simply click the ‘Add Custom Field’ button to save your changes and then publish or update your post.

    Troubleshooting: Can’t Find Custom Field in Dropdown on Post Edit Screen

    By default, WordPress only loads 30 custom fields in the dropdown menu on the post edit screen.

    If you are using WordPress themes and plugins that already use custom fields, then those might appear first in the dropdown menu, and you won’t be able to see your newly-created custom field.

    To fix this issue, you will need to add the following code to your theme’s functions.php file or by using WPCode (recommended):

    add_filter( 'postmeta_form_limit', 'meta_limit_increase' );
    function meta_limit_increase( $limit ) {
        return 50;
    }
    

    The above code will change that limit to 50. If you still can’t see your custom field, then you can try increasing that limit even further.

    Creating a User Interface for Custom Fields Using Advanced Custom Fields

    As you can see, once you add a custom field, you will have to select the field and enter its value each time you write a post.

    If you have many WordPress custom fields or multiple authors writing on your website, then this is not an ideal solution.

    Wouldn’t it be nice if you could create a user interface where users can fill in a form to add values to your custom fields?

    In fact, this is what so many popular WordPress plugins already do.

    For example, the SEO title and meta description box inside the popular All in One SEO plugin is a custom meta box:

    AIOSEO SEO title and description

    The easiest way to create a user interface for adding custom fields is by using the Advanced Custom Fields plugin.

    The first thing you need to do is install and activate the Advanced Custom Fields plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

    Upon activation, you need to visit the ACF » Field Groups page and click on the ‘Add New’ button.

    Add new field group

    A field group is like a container with a set of custom fields. It allows you to add multiple panels of custom fields.

    Now, you need to provide a title for your field group and click the ‘+ Add Field’ button in the top-right corner.

    Add new field

    You can now select a field type.

    Advanced Custom Fields allows you to create all sorts of fields, including text, image upload, number, dropdown, checkboxes, and more.

    Select field type and other details

    Next, you can scroll down to see other options for that particular field, like field name, field label, and default value. You can change them to your own requirements.

    You can also add multiple fields to your field group if you want. Once you are finished, just click on the ‘Save Changes’ button.

    View new field group

    Next, edit a post or create a new one, and you will see a new panel with your WordPress custom fields below the content editor.

    For detailed step-by-step instructions, you can see our guide on how to add custom meta boxes in WordPress posts and post types.

    How to Hide Empty Custom Fields With Conditional Statements

    So far, we have covered how to create a custom field and display it in your theme.

    Now let’s see how to check that the custom field is not empty before displaying it. To do that, we will modify our code to first check if the field has data in it:

    <?php 
    
    $mood = get_post_meta($post->ID, 'Mood', true);
    
    if ($mood) { ?>
    
    <p>Today's Mood: <? echo $mood; ?></p>
    
    <?php 
    
    } else {
    // do nothing;
    }
    
    ?>
    

    Don’t forget to replace Mood with your own custom field name.

    Adding Multiple Values to a Custom Field

    Custom fields can be reused in the same post to add multiple values. You just need to select the field again and add another value to the ‘Value’ box.

    Adding multiple values to a custom field

    However, the code we have used in the above examples will only be able to show a single value.

    To display all values of a custom field, we need to modify the code and make it return the data in an array. You will need to add the following code to your theme file:

    <?php 
    $mood = get_post_meta($post->ID, 'Mood', false);
    if( count( $mood ) != 0 ) { ?>
    <p>Today's Mood:</p>
    <ul>
    <?php foreach($mood as $mood) {
                echo '<li>'.$mood.'</li>';
                }
                ?>
    </ul>
    <?php 
    } else { 
    // do nothing; 
    }
    ?>
    

    Again, don’t forget to replace Mood with your own custom field name.

    In this example, you will notice that we have changed the last parameter of get_post_meta function to false. This parameter defines whether the function should return a single value or not. Setting it to false allows it to return the data as an array, which we then displayed in a foreach loop.

    How to Search Posts by Custom Field in WordPress

    WordPress’s default search doesn’t work with any custom fields on your website. It only uses the content to find the post you or your visitors are looking for on your site.

    However, SearchWP changes that by improving your WordPress search. It’s the best WordPress search plugin that goes beyond using the post content and indexes everything, including WordPress custom fields, PDF documents, custom tables, text, files, and more.

    You can adjust the search algorithm without editing code using SearchWP. Simply install the plugin and then head over to SearchWP » Algorithm from your WordPress admin area.

    After that, you need to go to the ‘Engines’ tab and then adjust the Attribute Relevance slider. This will change the importance given to each attribute during a search.

    Adjust the search relevance

    For instance, you can set the Custom Fields slider to maximum and adjust sliders for other attributes accordingly. This way, SearchWP will give preference to data in custom fields when searching for content in WordPress.

    Another advantage of using SearchWP is that works with some of the most popular custom field plugins, including Advanced Custom Fields (ACF), Meta Box, and Pods.

    For more details, you can read our beginner-friendly guide on how to improve WordPress search with SearchWP.

    Displaying Posts With a Specific Custom Key

    WordPress allows you to display posts with custom keys and their values. For example, if you are trying to create a custom archive page to display all posts with specific custom keys, then you can use the WP_Query class to query posts matching those fields.

    You can use the following code as a starting point:

    $args = array(
        'meta_key'   => 'Mood',
        'meta_value' => 'Happy'
    );
    $the_query = new WP_Query( $args );
     
    <?php 
    // the query
    $the_query = new WP_Query( $args ); ?>
     
    <?php if ( $the_query->have_posts() ) : ?>
     
        <!-- the loop -->
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <h2><?php the_title(); ?></h2>
            <?php the_content(); ?>
     
        <?php endwhile; ?>
        <!-- end of the loop -->
     
        <!-- pagination here -->
     
        <?php wp_reset_postdata(); ?>
     
    <?php else : ?>
        <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    

    Don’t forget to replace meta_key and meta_value parameters with your own values.

    How to Add Guest Author Name Using Custom Fields

    Do you want to add a guest post but don’t want to add a new user profile just for that post? An easier method is adding a guest author name as a custom field.

    To do this, you will need to add the following code to your theme’s functions.php file or use WPCode (recommended):

    add_filter( 'the_author', 'guest_author_name' );
    add_filter( 'get_the_author_display_name', 'guest_author_name' );
    function guest_author_name( $name ) {
    global $post;
    $author = get_post_meta( $post->ID, 'guest-author', true );
    if ( $author )
    $name = $author;
    return $name;
    }
    

    For more details, please see our guide on pasting snippets from the web into WordPress.

    This code hooks a function to the_author and get_the_author_display_name filters in WordPress.

    The function first checks for the guest author’s name. If it exists, then it replaces the author’s name with the guest author’s name.

    Now you will need to edit the post where you want to display the guest author’s name. Go to the Custom Fields meta box, add your guest author name, and finally click on the ‘Add Custom Field’ button.

    Guest author custom field

    For more details, see our article on how to rewrite guest author names with custom fields in WordPress.

    How to Display Contributors to an Article Using Custom Fields

    On many popular blogs and news sites, many authors contribute to writing a single article. However, WordPress only allows a single author to be associated with a post.

    One way to solve this problem is by using the Co-Authors Plus plugin. To learn more, see our guide on how to add multiple authors to a WordPress post.

    Another method is adding contributors as a custom field.

    First, you need to edit the post where you want to display co-authors or contributors. Then, scroll down to the Custom Fields meta box and add author names as co-author custom fields.

    Add coauthor custom fields

    Now, you need to add this code to your theme files where you want to show co-authors:

    <?php 
     
    $coauthors = get_post_meta($post->ID, 'co-author', false);
    if( count( $coauthors ) != 0 ) { ?>
    <ul class="coauthors">
    <li>Contributors</li>
    <?php foreach($coauthors as $coauthors) { ?>
               <?php echo '<li>'.$coauthors.'</li>' ;
                }
                ?>
    </ul>
    <?php 
    } else { 
    // do nothing; 
    }
    ?>
    

    To display author names separated by commas, you can add the following custom CSS:

    .coauthors ul { 
    display:inline;
    }
    .coauthors li { 
    display:inline;
    list-style:none;
    }
    .coauthors li:after { 
    content:","
    }
    .coauthors li:last-child:after {
        content: "";
    }
    .coauthors li:first-child:after {
        content: ":";
    }
    

    This is how it looked on our demo site.

    Coauthors custom fields preview

    How to Display Custom Fields Outside the Loop in WordPress

    What if you need to show custom fields in the sidebar of a single post?

    To display the custom fields outside the WordPress loop, you can add the following code to your theme files:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'key', true);
    wp_reset_query();
    ?>
    

    Don’t forget to replace key with your custom field name.

    Display a Custom Header, Footer, Sidebar Using Custom Fields

    Usually, most WordPress themes use the same header, footer, and sidebar on all pages.

    There are also many ways to show different sidebars, headers, or footers for different pages on your website. You can see our guide on how to display a different sidebar for each WordPress post or page.

    One way to do this is by using custom fields. Just edit the post or page where you want to show a different sidebar and then add the sidebar as a custom field.

    Add sidebar custom field

    Now you need to edit your WordPress theme file, such as single.php, where you want to display a custom sidebar. You will be looking for the following code:

    <?php get_sidebar(); ?>
    

    Replace this line with the following code:

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $sidebar = get_post_meta($postid, "sidebar", true);
    get_sidebar($sidebar);
    wp_reset_query();
    ?>
    

    This code simply looks for the sidebar custom field and then displays it in your theme. For example, if you add webpage as your sidebar custom field, then the code will look for a sidebar-webpage.php file to display.

    You will need to create the sidebar-webpage.php file in your theme folder. You can copy the code from your theme’s sidebar.php file as a starting point.

    Manipulating RSS feed Content With Custom Fields

    Want to display additional metadata or content to your RSS feed users? Using custom fields you can manipulate your WordPress RSS feed and add custom content into your feeds.

    First, you need to add the following code to your theme’s functions.php file or use WPCode (recommended):

    function wpbeginner_postrss($content) {
    global $wp_query;
    $postid = $wp_query->post->ID;
    $coolcustom = get_post_meta($postid, 'coolcustom', true);
    if(is_feed()) {
    if($coolcustom !== '') {
    $content = $content."<br /><br /><div>".$coolcustom."</div>
    ";
    }
    else {
    $content = $content;
    }
    }
    return $content;
    }
    add_filter('the_excerpt_rss', 'wpbeginner_postrss');
    add_filter('the_content', 'wpbeginner_postrss');
    

    Now, just create a custom field called ‘coolcustom’ and add any value you like. You can use it to display advertisements, images, text, or anything you want.

    For more details, please see our guide on how to copy and paste code from the web into WordPress.

    How to Manipulate RSS Feed Title With Custom Fields

    Sometimes you may want to add extra text to a post title for RSS feed users. For example, this can be handy if you are publishing a sponsored post or a guest post.

    First, you need to add the following code to your theme’s functions.php file or use WPCode to add the custom code snippet without breaking your website:

    function wpbeginner_titlerss($content) {
    global $wp_query;
    $postid = $wp_query->post->ID;
    $gpost = get_post_meta($postid, 'guest_post', true);
    $spost = get_post_meta($postid, 'sponsored_post', true);
    
    if($gpost !== '') {
    $content = 'Guest Post: '.$content;
    }
    elseif ($spost !== ''){
    $content = 'Sponsored Post: '.$content;
    }
    else {
    $content = $content;
    }
    return $content;
    }
    add_filter('the_title_rss', 'wpbeginner_titlerss');
    

    Next, you need to edit the post where you want to display the extra text in the title field.

    Then, add guest_post and sponsored_post as custom fields.

    Add guest post custom field

    If either of these two custom fields is found with a value “true”, then the code will add the appropriate text before the title. This technique can be used in many ways to fit whatever you like.

    Want to learn more cool RSS feed hacks? See our guide on how to add content and manipulate your WordPress RSS feeds.

    How to Set Expiration Date for Posts in WordPress Using Custom Fields

    Want to set an expiration date for some posts on your WordPress site? This comes in handy when you want to publish content only for a specific period like running surveys or limited-time offers.

    One way to do this is by manually removing the post content or by using a plugin like Post Expirator.

    Another option is using custom fields to automatically expire posts after a specific time. You will need to edit your theme files and modify the WordPress loop like this:

    <?php
    if (have_posts()) :
    while (have_posts()) : the_post();
    $expirationtime = get_post_meta($post->ID, "expiration", false);
    if( count( $expirationtime ) != '' ) {
    if (is_array($expirationtime)) {
    $expirestring = implode($expirationtime);
    }
    
    $secondsbetween = strtotime($expirestring)-time();
    if ( $secondsbetween >= 0 ) {
    echo 'This post will expire on ' .$expirestring.'';
    the_content();
    } else {
    echo "Sorry this post expired!"
    }
    } else {
    the_content();
    }
    endwhile;
    endif;
    ?>
    

    Note: You will need to edit this code to match your theme.

    After adding this code, you can add the expiration custom field to the post you want to expire. Make sure you add the time in this format mm/dd/yyyy 00:00:00.

    Adding an expiration date using custom field

    How to Style Individual Posts Using Custom Fields

    Want to change the look of an individual post using CSS? WordPress automatically assigns each post its own class, which you can use to add custom CSS.

    However, by using custom fields, you can add your own custom classes and then use them to style posts differently.

    First, you need to edit a post that you would like to style differently. Go to the Custom Fields box and add the post-class custom field.

    Post class custom field

    Next, you need to edit your WordPress theme files and add this code at the beginning of the WordPress loop:

    <?php $custom_values = get_post_meta($post->ID, 'post-class'); ?>
    

    Now you need to find the line with the post_class() function.

    Here is how it looked in our demo theme:

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    

    You must change this line to include your custom field value, like this:

    <article id="post-<?php the_ID(); ?>" <?php post_class($custom_values); ?>>
    

    Now if you examine the post’s source code using the Inspect tool, then you will see your custom field CSS class added to the post-class.

    Post class preview

    You can now can use this CSS class to add custom CSS and style your post differently.

    We hope this article helped you learn more about WordPress custom fields. You may also want to see our guide on how to add custom meta fields to custom taxonomies in WordPress and the best WordPress page builder plugins to help you design your website the way you want.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post WordPress Custom Fields 101: Tips, Tricks, and Hacks first appeared on WPBeginner.

  • How to Disable Automatic Update Email Notification in WordPress

    Do you want to disable automatic update email notifications in WordPress?

    By default, WordPress sends email notifications for automatic updates of WordPress plugins, themes, and the core itself. These notification emails can get annoying.

    In this article, we will show you how to easily disable automatic update email notifications in WordPress.

    Disabling automatic update email notifications in WordPress

    About Automatic Update Notifications in WordPress

    WordPress is an open-source content management platform that is regularly maintained and updated.

    Some of these updates are automatically installed, and you will receive an email notification that your site has been updated.

    Email notification preview after an auto-update

    Similarly, WordPress also allows you to enable automatic updates for WordPress plugins and themes. This means that you can spend less time updating plugins and more time growing your business.

    You can enable automatic updates for plugins that you trust by visiting the Plugins » All Plugins page in your WordPress admin dashboard.

    Simply click on the ‘Enable auto-updates’ link next to the plugin that you want to update itself.

    Enable automatic updates for WordPress plugins

    For WordPress themes, you can visit the Appearance » Themes page and click on a theme.

    This will bring up a theme information popup where you must click on ‘Enable auto-updates’.

    Enable theme auto-updates

    WordPress will send you an email notification when any of your plugins, theme, or WordPress core is updated.

    This can get annoying, particularly for users who manage multiple WordPress websites. Wouldn’t it be nice if you could control and turn off these email notifications?

    Let’s take a look at how to easily disable automatic update email notifications in WordPress. You can use the quick links below to jump to the method you want to use:

    Method 1: Disable Automatic Update Email Notification Using Code (Recommended)

    This method requires you to add code to your WordPress files. If you haven’t done this before, then take a look at our beginner’s guide on pasting snippets from the web into WordPress.

    You can manually add the code below to your theme’s functions.php file. But this can be tricky since a mistake can bring down your whole website. Plus, if you update your theme, then any custom code snippets will be erased.

    We will show you a better approach below, which is using a code snippets plugin.

    1. Disable Auto Update Notification Emails for WordPress Core, Themes, and Plugins

    Luckily, there is an easy and safe way to disable auto update notification emails in WordPress, and that’s using the WPCode plugin.

    WPCode WordPress code snippets plugin

    WPCode lets you easily add custom code snippets in WordPress without editing your theme’s functions.php file.

    Plus, it has a full code library inside the plugin that includes ready-to-use, verified code snippets for popular feature requests like disabling automatic update emails, removing the WordPress version number, disabling comments, and more.

    First, you need to install and activate the free WPCode plugin. For step-by-step instructions, see our tutorial on how to install a WordPress plugin.

    Once the plugin is activated, you need to go to Code Snippets » Library from your WordPress admin dashboard.

    Then, search for the ‘Disable Automatic Updates Emails’ snippet and click on the ‘Use snippet’ button.

    Search for the Disable Automatic Updates Emails snippet in WPCode

    WPCode will then automatically add the code and set the proper insertion method.

    The snippet has three filters, with one for each type of auto-update email: WordPress core, WordPress plugins, and WordPress themes.

    Disable Automatic Updates Emails snippet in WPCode

    If you don’t want to use a particular filter, simply add a // at the beginning of the filter line.

    For example, if you still want to get auto-update emails for WordPress plugins, add a // to the plugin, and the filter will stop it from executing.

    Edit filters you don't want to execute in WPCode

    After that, all you have to do is toggle the switch from ‘Inactive’ to ‘Active’.

    Then, click the ‘Update’ button.

    Switch the code snippet to Active and click Update in WPCode

    Now you will no longer get automatic update emails from WordPress.

    2. Disable Auto Update Notification Emails for Core Updates

    You can also use WPCode to disable notification emails for automatic WordPress core updates. Instead of choosing an existing code snippet, you will need to add this code as a custom snippet:

    add_filter( 'auto_core_update_send_email', 'wpb_stop_auto_update_emails', 10, 4 );
    
    function wpb_stop_update_emails( $send, $type, $core_update, $result ) {
    if ( ! empty( $type ) && $type == 'success' ) {
    return false;
    }
    return true;
    }
    

    For more instructions, you can see our guide on how to add custom code in WordPress.

    3. Disable Auto Update Notification Emails for Plugins

    Just add the following code to disable notification emails for automatic updates of WordPress plugins:

    add_filter( 'auto_plugin_update_send_email', '__return_false' );
    

    4. Disable Notification Emails for WordPress Theme Updates

    Finally, you can add the following code to disable notification emails for automatic updates of WordPress themes:

    add_filter( 'auto_theme_update_send_email', '__return_false' );
    

    Method 2: Disable Automatic Update Email Notification Using a Plugin

    Next, we will show you how to disable automatic update email notifications using two different email plugins.

    1. Manage Notification Emails

    The first thing you need to do is install and activate the Manage Notification Emails plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

    Upon activation, you need to visit the Settings » Notification emails page. This is where the plugin allows you to manage all WordPress notification emails, including auto-update notifications.

    Disable email notifications

    Simply scroll down to the auto-update options and uncheck the box next to the notifications you want to disable.

    Finally, don’t forget to click on the ‘Save Changes’ button to store your settings.

    2. WP Mail SMTP

    Another plugin you can use to disable automatic update email notifications is WP Mail SMTP. It’s the best SMTP service for WordPress and ensures your emails are delivered to your inbox.

    WP Mail SMTP lets you easily manage the emails sent by WordPress through its Email Controls. However, you will need the WP Mail SMTP Pro license to unlock the Email Controls option.

    Next, you will need to install and activate WP Mail SMTP Pro on your website. You can check out our guide on how to install a WordPress plugin for more details.

    Once the plugin is active, navigate to WP Mail SMTP » Settings from your WordPress admin panel and click the ‘Email Controls’ tab.

    After that, scroll down to the ‘Automatic Updates’ section and disable email notifications for plugins, themes, WP core status, and full log.

    Disable Update Email Notifications in WP Mail SMTP

    When you are done, don’t forget to click the ‘Save Settings’ button.

    That’s all. You have successfully disabled WordPress auto-update email notifications for your website.

    Rolling Back WordPress Updates if Something Goes Wrong

    Because WordPress plugins run on many independent WordPress hosting and server configurations, sometimes a plugin update may break a feature on your website or make it inaccessible.

    This is easy to troubleshoot and fix. First, you need to figure out which plugin has caused the issue by deactivating all WordPress plugins and reactivating them one by one.

    Once you have isolated the plugin causing the issue, you can use the WP Rollback plugin. It allows you to switch to the previous version of a WordPress plugin or theme.

    For details, you can see our guide on how to roll back WordPress plugins and themes with step-by-step instructions.

    Improving WordPress Email Deliverability

    Even if you disable WordPress auto-update emails, there are other WordPress notification emails that you may not want to miss.

    For instance, if you run a WooCommerce store, then you will want to receive notifications when a new order is placed.

    Similarly, if you sell an online course or run a membership website, then you might want to receive email alerts when new users sign up.

    You will also want to make sure that emails sent to users are delivered, including forgotten password emails, payment receipt emails, and order confirmation notifications.

    To send emails, WordPress uses the PHP mail function. This function is easily misused by spammers, and your emails may end up in the spam folder.

    To make sure all your important WordPress notification emails reach your users’ inboxes, you will need a proper SMTP service to send emails.

    This is where the WP Mail SMTP plugin comes in. It uses an SMTP service to send all your WordPress notification emails.

    You can use it with a paid SMTP service provider or a free SMTP service like Gmail combined with the free version of the WP Mail SMTP plugin.

    For more details, see our guide on How to set up WP Mail SMTP on your WordPress site.

    We hope this article helped you learn how to disable automatic update email notifications in WordPress. You may also want to see our guide on how to get a free business email address and our comparison of the best email marketing services to grow your sales.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Disable Automatic Update Email Notification in WordPress first appeared on WPBeginner.

  • How to Create a Custom WordPress Block (Easy Way)

    Do you want to create a custom WordPress block for your website?

    While WordPress comes with a lot of basic blocks for creating content, you might need something more specific for your website.

    In this article, we will show you two ways to create custom Gutenberg blocks for your WordPress site.

    How to create a custom Gutenberg block in WordPress

    Why Create a Custom WordPress Block?

    WordPress comes with an intuitive block editor that allows you to easily build your posts and pages by adding content and layout elements as blocks.

    By default, WordPress ships with several commonly-used blocks. WordPress plugins may also add their own blocks that you can use.

    However, sometimes you may want to create your own custom block to do something specific on your WordPress website because you can’t find a blocks plugin that works for you.

    With custom blocks, you can add unique features and functionality to your website that may not be available in pre-built blocks. This can help automate processes or make content creation for your WordPress blog more efficient.

    For example, you could create a custom block to display testimonials and then easily insert and manage that block without any coding knowledge.

    Having said that, let’s see how to easily create a completely custom block in WordPress.

    For this tutorial, we will be showing you two methods to create a custom block. You can use the quick links below to jump to the method of your choice:

    If you are a beginner and inexperienced with coding, then this method is for you.

    WPCode is the best WordPress code snippets plugin on the market that makes it super easy and safe to add custom code to your website.

    It comes with the block snippets feature that allows you to easily create custom blocks for your WordPress site without writing any code.

    First, you need to install and activate the WPCode plugin. For detailed instructions, you may want to see our beginner’s guide on how to install a WordPress plugin.

    Note: WPCode also offers a free version that you can use to add custom code to your website. However, you will need the Pro version of the plugin to unlock the custom block snippets feature.

    Upon activation, you need to head over to the Code Snippets » + Add Snippet page from the WordPress admin sidebar.

    Once you are there, click the ‘Use Snippet’ button under the ‘Add Your Custom Code (New Snippet)’ option.

    Add new snippet

    This will take you to the ‘Create Custom Snippet’ page, where you can start by typing a name for the custom block that you are about to create.

    Once you have done that, just select the ‘Blocks Snippet’ option from the ‘Code Type’ dropdown menu in the right corner of the screen.

    This will display the ‘Edit with Block Editor’ button in the ‘Code Preview’ box.

    Choose the Block Snippets option and click the Edit with block editor button

    Simply click on this button to launch the block editor.

    Now, a prompt will appear on your screen asking you to save the code snippet to load it in the block editor. Just click on the ‘Yes’ button to move ahead.

    Choose the Yes option in the Save Snippet prompt

    Now that you are in the block editor, you can easily create a custom block using the pre-made blocks available in the block menu.

    For this tutorial, we will be creating a custom block for adding testimonials on your site.

    First, you need to click the ‘+’ button in the top left corner of the screen to open up the block menu.

    From here, drag and drop the Heading block into the block editor interface and name it ‘Testimonials’.

    Add heading block for the testimonials block

    Next, you can use the paragraph, pull-quote, or quote blocks to add testimonials from different clients on your website.

    You can even use the image, site logo, social icons, or site tagline blocks to further customize your Testimonials block.

    Add testimonial quote in the custom block

    You can also customize the size, text color, or background color of your testimonials from the block panel on the right side of the screen.

    Once you are done, don’t forget to click the ‘Update’ button at the top to store your custom block settings.

    Next, just click on the ‘Return to WPCode Snippet’ button at the top to be redirected to the ‘Edit Snippet’ page.

    Click Return to WPCode snippet button at the top

    Once you are there, scroll down to the ‘Insertion’ section and choose the ‘Auto Insert’ mode.

    Upon activation of the code snippet, your custom block will be automatically added to where you choose to insert it on your website.

    Choose an insertion method

    Next, you have to configure the location of the custom block you created.

    To do this, simply click the ‘Location’ dropdown menu in the ‘Insertion’ section and switch to the ‘Page-Specific’ tab. From here, you can now choose the ‘Insert After Post’ option if you want to show your Testimonials block after the post ends.

    Once you do that, you can also configure the number of posts after which the testimonial block should appear. For example, if you type in the number 3, then the Testimonials block will appear in every third post.

    You can also display the block in between different paragraphs, after post excerpts, and more.

    Choose a block location

    However, if you don’t find the block location that you are looking for, then you can also create your own conditional logic rule to add the custom block to your preferred place.

    To do this, scroll down to the ‘Smart Conditional Logic’ section and toggle on the ‘Enable Logic’ switch.

    Next, you must click the ‘Add New Group’ button to start creating a conditional logic rule.

    Enable the conditional logic option

    For example, if you only want to show the custom block you created on a specific page or post, then you will have to select the ‘Page URL’ option from the dropdown menu on the right.

    After that, you can leave the dropdown menu in the middle as it is and then add the URL of the WordPress page/post of your choice into the field on the left.

    You can also configure your conditional logic rule to only display the custom block on a specific page, logged-in users, on WooCommerce store pages, Easy Digital Downloads pages, specific dates, and more.

    Add conditional logic rule

    Once you are done, scroll back to the top of the page and toggle the ‘Inactive’ switch to ‘Active’. Then, click the ‘Update’ button to store your settings.

    Your custom block will now be automatically added to all the locations that you selected for the block snippet.

    Activate custom block

    Keep in mind that the custom block you created won’t be displayed as an option in the block menu of the Gutenberg editor.

    You will have to configure the block settings by visiting the Code Snippets page from the WordPress dashboard and clicking the ‘Edit’ link under the block snippet.

    This will open the ‘Edit Snippet’ page, where you can customize the block or change its location and conditional logic rules easily.

    Edit block snippet

    Now visit your website to view the custom block that you created in action.

    Here is our custom Testimonials block on our demo website.

    Testimonials block preview

    Method 2: Create Custom Blocks for WordPress Using Genesis Custom Code Plugin (Free)

    If you are an intermediate user and looking for a free solution, then this method is for you. Keep in mind that you will need to be familiar with HTML and CSS to follow the instructions in this method.

    First, you need to install and activate the Genesis Custom Blocks plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

    Made by the people behind WP Engine hosting, this plugin provides developers with easy tools to quickly create custom blocks for their projects.

    For the sake of this tutorial, we will build a Testimonials block.

    Step 1: Create a Custom Block for WordPress

    First, you need to head over to Custom Blocks » Add New page from the left sidebar of your admin panel.

    Creating a new custom block

    This will bring you to the Block Editor page, where you will be creating a custom block for your WordPress site.

    From here, you can start by giving a name to your block.

    Block name

    Now on the right side of the page, you will find the block properties that you can configure.

    Here you can choose an icon for your block, add a category, and add keywords.

    Configure block settings

    The slug will be auto-filled based on your block’s name, so you don’t have to change it. However, you may write up to 3 keywords in the ‘Keywords’ text field so that your block can be easily found.

    Now, it’s time for you to add some fields to your block. You can add different types of fields like text, numbers, email addresses, URLs, colors, images, checkboxes, radio buttons, and more.

    We will add 3 fields to our custom Testimonials block: an image field for the photo of the reviewer, a textbox for the reviewer name, and a text area field for the testimonial text.

    Just click on the ‘+’ button to insert the first field.

    Add block field

    This will open up some options for the field in the right column. Let’s take a look at each of them.

    • Field Label: You can use any name of your choice for the field label. Let’s name our first field ‘Reviewer Image’.
    • Field Name: The field name will be generated automatically based on the field label. We will use this field name in the next step, so make sure it’s unique for every field.
    • Field Type: Here, you can select the type of field. We want our first field to be an image, so we will pick ‘Image’ from the dropdown menu.
    • Field Location: You can decide whether you want to add the field to the editor or the inspector.
    • Help Text: You can add some text to describe the field. This is not required if you are creating this block for your personal use but may be helpful for multi-author blogs.

    You may also see some additional options based on the field type you choose. For example, if you select a text field, then you will get extra options like placeholder text and character limit.

    Following the above process, let’s add 2 other fields for our Testimonials block by clicking the ‘+’ button.

    In case you want to reorder the fields, then you can do that by dragging them using the handle on the left side of each field label. To edit or delete a particular field, you need to click the field label and edit the options in the right column.

    Publish block

    Once you are done, just click on the ‘Publish’ button on the right side of the page to save your custom Gutenberg block.

    Step 2: Create a Custom Block Template

    Although you created the custom WordPress block in the last step, it won’t work until you create a block template.

    The block template determines exactly how the information entered into the block is displayed on your website. You get to decide how it looks by using HTML and CSS, or even PHP code if you need to run functions or do other advanced things with the data.

    There are two ways to create a block template. If your block output is in HTML/CSS, then you can use the built-in template editor.

    On the other hand, if your block output requires some PHP to run in the background, then you will need to manually create a block template file and upload it to your theme folder.

    Method 1: Using Built-in Template Editor

    On the custom block edit screen, simply switch to the ‘Template Editor’ tab and enter your HTML under the markup tab.

    Block template editor

    You can write your HTML and use double curly brackets to insert block field values.

    For instance, we used the following HTML for the sample block we created above:

    <div class="testimonial-item">
    <img src="{{reviewer-image}}" class="reviewer-image">
    <h4 class="reviewer-name">{{reviewer-name}}</h4>
    <div class="testimonial-text">{{testimonial-text}}</div>
    </div>
    

    After that, just switch to the ‘CSS’ tab to style your block output markup.

    Enter your block template CSS

    Here is the sample CSS we used for our custom block:

    .reviewer-name { 
        font-size:14px;
        font-weight:bold;
        text-transform:uppercase;
    }
    
    .reviewer-image {
        float: left;
        padding: 0px;
        border: 5px solid #eee;
        max-width: 100px;
        max-height: 100px;
        border-radius: 50%;
        margin: 10px;
    }
    
    .testimonial-text {
        font-size:14px;
    }
    
    .testimonial-item { 
     margin:10px;
     border-bottom:1px solid #eee;
     padding:10px;
    }
    

    Method 2: Manually Uploading Custom Block Templates

    This method is recommended if you need to use PHP to interact with your custom block fields. You will basically need to upload the editor template directly to your theme.

    First, you need to create a folder on your computer and name it using your custom block name slug.

    For instance, our demo block is called Testimonials, so we will create a testimonials folder.

    Block template folder

    Next, you need to create a file called block.php using a plain text editor. This is where you will put the HTML / PHP part of your block template.

    Here is the sample template we used for our example:

    <div class="testimonial-item <?php block_field('className'); ?>">
    <img class="reviewer-image" src="<?php block_field( 'reviewer-image' ); ?>" alt="<?php block_field( 'reviewer-name' ); ?>" />
    <h4 class="reviewer-name"><?php block_field( 'reviewer-name' ); ?></h4>
    <div class="testimonial-text"><?php block_field( 'testimonial-text' ); ?></div>
    </div>
    

    Now you may have noticed how we used the block_field() function to fetch data from a block field.

    We have wrapped our block fields in the HTML we want to use to display the block. We have also added CSS classes so that we can style the block properly.

    Don’t forget to save the file inside the folder you created earlier.

    Next, you need to create another file using the plain text editor on your computer and save it as block.css inside the folder you created.

    We will use this file to add CSS needed to style our block display. Here is the sample CSS we used for this example:

    .reviewer-name { 
        font-size:14px;
        font-weight:bold;
        text-transform:uppercase;
    }
    
    .reviewer-image {
        float: left;
        padding: 0px;
        border: 5px solid #eee;
        max-width: 100px;
        max-height: 100px;
        border-radius: 50%;
        margin: 10px;
    }
    
    .testimonial-text {
        font-size:14px;
    }
    
    .testimonial-item { 
     margin:10px;
     border-bottom:1px solid #eee;
     padding:10px;
    }
    

    Don’t forget to save your changes.

    Your block template folder will now have two template files inside it.

    block template files

    After that, you need to upload your block folder to your website using an FTP client or the File Manager app inside your WordPress hosting account’s control panel.

    Once connected, navigate to the /wp-content/themes/your-current-theme/ folder.

    Create blocks folder inside your WordPress theme folder

    If your theme folder doesn’t have a folder named ‘blocks’, then go ahead and create a new directory and call it blocks.

    Next, you have to upload the folder you created on your computer to the blocks folder.

    Uploaad block template files

    That’s all! You have successfully created manual template files for your custom block.

    Step 3: Preview Your Custom Block

    Before you can preview your HTML/CSS, you will need to provide some test data that can be used to display a sample output.

    Inside the WordPress admin area, edit your block and switch to the ‘Editor Preview’ tab. Here, you need to enter some dummy data.

    Editor preview

    This data won’t be a part of your custom block and will only be used for previewing the changes you made using HTML and CSS.

    Once you have added the data, don’t forget to click on the ‘Update’ button to save your changes.

    Save your template changes

    If you don’t click the ‘Update’ button, then you won’t be able to see the preview of your custom block.

    You can now switch to the ‘Front-end Preview’ tab to see how your block will look on the front end of your WordPress website.

    Front-end preview of your website

    If everything looks good to you, then you can update your block again to save any unsaved changes.

    Step 4: Using Your Custom Block in WordPress

    You can now use your custom block in WordPress like you would any other block.

    Simply edit any post or page where you want to use this block. Then, click the ‘+’ button in the top left corner to open up the block menu.

    Inseting custom block in posts and pages

    From here, find your block by typing in its name or keywords and then add it to the page/post.

    After you insert the custom block into the content area, you will see the block fields you created earlier.

    Block fields preview

    You can fill out the block fields as needed.

    As you move away from the custom WordPress block to another one, the editor will automatically show a live preview of your block.

    Block preview inside the block editor

    You can now save your post and page and preview it to see your custom block in action on your website.

    Here’s how the Testimonials block looks on our test site.

    Custom block live preview

    We hope this article helped you learn how to easily create custom Gutenberg blocks for your WordPress website. You may also want to see our guide on how to create a custom WordPress theme from scratch or see our expert picks for the best block themes for full site editing.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Create a Custom WordPress Block (Easy Way) first appeared on WPBeginner.

  • How to Add a Dynamic Copyright Date in WordPress Footer

    Do you want to add a dynamic copyright date in your WordPress website’s footer?

    A website with an outdated copyright date can look unprofessional. Adding a dynamic copyright date to your site’s footer shows visitors that your website is up-to-date and regularly maintained.

    In this article, we will show you how to easily add a dynamic copyright date in the WordPress footer.

    Adding dynamic copyright date in WordPress footer

    Why Add a Dynamic Copyright Date in WordPress Footer?

    A copyright date typically covers the current year or range of years in which the content, design, and code of your WordPress website are protected by copyright laws.

    The copyright date on your website should be current, but manually updating it takes time, and you might forget to do it.

    That’s where a dynamic copyright date can help. It will automatically update to ensure that the date is accurate and meets the copyright laws of different countries.

    It also helps protect your content from copyright infringement and plagiarism.

    Plus, an updated copyright date also signals to search engines that your website is well-maintained and active. This can help improve your website’s search engine rankings and attract more traffic to your site.

    In this article, we will show you how to easily add a dynamic copyright date in the WordPress footer. You can use the quick links below to jump to the method you want to use:

    If you want to generate a dynamic copyright date that covers all the years from the start of your WordPress blog until the current year, then this method is for you. It works by using the published date of your oldest post and your newest post.

    To add a dynamic copyright date to your WordPress footer, many tutorials will tell you to add custom code to your theme’s functions.php file. However, the smallest error while typing the code can break your website.

    That’s why we recommend using WPCode, which is the best WordPress code snippets plugin on the market. It is the easiest and safest way to add code to your website.

    First, you will need to install and activate the WPCode plugin. For more instructions, you may want to see our tutorial on how to install a WordPress plugin.

    Note: You can also use the free WPCode plugin for this tutorial. However, upgrading to the Pro version will give you access to a cloud library of code snippets, smart conditional logic, and more.

    Upon activation, just visit the Code Snippets » + Add Snippet page from the WordPress admin sidebar.

    From here, go to the â€˜Add Your Custom Code (New Snippet)’ option and click on the ‘Use Snippet’ button under it.

    Add new snippet

    This will direct you to the ‘Create Custom Snippet’ page, where you can start by typing a name for your code snippet.

    Keep in mind that this name won’t be displayed on the front end and is only used for identification purposes.

    After that, you need to choose ‘PHP Snippet’ as the Code Type from the dropdown menu in the right corner.

    Choose PHP as code type for the dynamic copyright date code

    Once you have done that, simply copy and paste the following code into the ‘Code Preview’ box:

    if ( ! function_exists( 'wpb_copyright' ) ) {
    	function wpb_copyright() {
    		// Cache the output so we don't have to run the query on every page load.
    		$output = get_transient( 'wpb_copyright_text' );
    		if ( false !== $output ) {
    			// Return the cached output.
    			return $output;
    		}
    		global $wpdb;
    		$copyright_dates = $wpdb->get_results(
    			"SELECT YEAR(min(post_date_gmt)) AS firstdate, YEAR(max(post_date_gmt)) AS lastdate FROM $wpdb->posts WHERE post_status = 'publish'"
    		);
    		$output          = '';
    		if ( $copyright_dates ) {
    			$output = '© ' . $copyright_dates[0]->firstdate;
    			if ( $copyright_dates[0]->firstdate !== $copyright_dates[0]->lastdate ) {
    				$output .= '-' . $copyright_dates[0]->lastdate;
    			}
    			// Set the value as a transient so we only run the query 1x per day.
    			set_transient( 'wpb_copyright_text', $output, DAY_IN_SECONDS );
    		}
    
    		return $output;
    	}
    }
    
    echo wpb_copyright();
    

    Upon activation, this code will automatically fetch data and display your copyright date according to the oldest and newest post on your website.

    Next, scroll down to the ‘Insertion’ section and choose the ‘Shortcode’ method.

    We are using this method because we want to specifically add code to the WordPress footer.

    Use the shortcode method

    Finally, scroll back to the top and toggle the ‘Inactive’ switch to ‘Active’.

    Once you have done that, just click the ‘Save Snippet’ button to store your settings.

    Save the code snippet for adding dynamic copyright date

    Now, you have to scroll back to the ‘Insertion’ section and copy the shortcode by clicking on the ‘Copy’ button next to it.

    Keep in mind that you won’t be able to copy the shortcode until you have activated and saved the code snippet.

    Copy the shortcode for the dynamic copyright date

    Add Dynamic Copyright Date to the WordPress Footer Using a Widget

    You now need to add the shortcode to your WordPress footer. This method is for you if you are using a classic theme without the full site editor.

    Once you have copied the shortcode, head over to the Appearance » Widgets page from the WordPress admin sidebar.

    From here, scroll down to the ‘Footer’ tab and expand it.

    For this tutorial, we are using the Hestia Pro theme. Depending on the theme that you are using, your widgets page may look a bit different.

    Next, you need to click on the ‘+’ button in the top left corner of the screen and look for the Shortcode block.

    Upon finding it, just add the block to the ‘Footer’ tab and then paste the WPCode shortcode into it.

    Add shortcode into the footer tab

    Finally, click the ‘Update’ button at the top to save your changes.

    Now, you can visit your website to check out the dynamic copyright date in action.

    Preview for dynamic copyright date in WordPress footer

    Add a Dynamic Copyright Date in a Block-Based Theme

    If you are using a block-based theme on your WordPress website, then you can use this method to add the copyright shortcode to the footer.

    First, you need to visit the Appearance » Editor page from the WordPress admin sidebar. This will launch the full site editor on your screen.

    From here, choose the Footer section and then click on the ‘+’ button in the top left corner of the screen.

    Next, simply find and add the Shortcode block to your preferred area in the footer.

    Once you have done that, paste the dynamic copyright date shortcode into the block.

    Add copyright date shortcode into the FSE

    Finally, don’t forget to click the ‘Save’ button at the top to store your settings.

    You can now visit your website to check out the dynamic copyright date in action.

    Copyright date in fse

    If you don’t want to use code on your website, then this method is for you.

    First, you will need to install and activate the Auto Copyright Year Updater plugin. For details, you may want to see our guide on how to install a WordPress plugin.

    Upon activation, the plugin will automatically fetch data for your copyright date. Keep in mind that the plugin only displays the current year and does not show the range of years that the site has been used.

    To display the copyright date, you will now have to add a shortcode to the website footer.

    Add Dynamic Copyright Date in a Classic Theme

    If you are using a classic theme that doesn’t use the full site editor, then this method is for you.

    First, you need to visit the Appearance » Widgets page from the WordPress admin sidebar. Once you are there, scroll down to the ‘Footer’ tab and expand it.

    For this tutorial, we are using the Hestia Pro theme, so your widgets may look a bit different depending on the theme that you are using.

    Next, click on the ‘+’ button in the top left corner of the screen and find the Shortcode block.

    Simply add the block to the ‘Footer’ tab and then copy and paste the following shortcode into it to display the copyright date:

    [cr_year]

    Add plugin shortcode in the footer widget

    If you also want to add a copyright symbol along with the date, then you should add the following shortcode as well.

    [cr_symbol]

    Finally, click the ‘Update’ button at the top to save your changes.

    Now, you can visit your website to check out the dynamic copyright date in action.

    Plugin shortcode preview

    Add Dynamic Copyright Date in a Block-Based Theme

    If you are using a block-based theme with the full site editor, then you can insert the dynamic copyright shortcode with this method.

    You need to head to the Appearance » Editor page from the WordPress admin sidebar.

    Once you are there, choose the ‘Footer’ section and then click on the ‘+’ button in the top left corner of the screen. Then, look for and add the Shortcode block.

    After that, add the following shortcode into the block to display the copyright date on your website:

    [cr_year]

    Add plugin shortcode

    If you want to add a copyright symbol along with the dates, then simply copy and paste the following shortcode into the block as well:

    [cr_symbol]

    Finally, click the ‘Save’ button at the top to store your settings.

    Now, you can visit your website to see the dynamic copyright date in action.

    Copyright date preview with plugin

    We hope this article helped you learn how to add dynamic copyright dates in the WordPress footer. You may also want to see our tutorial on how to use a headline analyzer in WordPress to improve SEO titles and our top picks for the best WordPress plugins to grow your site.

    If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

    The post How to Add a Dynamic Copyright Date in WordPress Footer first appeared on WPBeginner.