April 2022

Varnish Cache

#!/bin/sh
sudo -i
apt update && apt upgrade
#Install Apache webserver
apt install apache2
systemctl start apache2
systemctl status apache2
#Being a webserver, Apache listens on port 80 by default. Use the netstat command as shown to verify this.
sudo netstat -pnltu
#Install Varnish HTTP Accelerator
apt install varnish
systemctl start varnish
systemctl status varnish
#Configuring Apache and Varnish HTTP Cache
nano /etc/apache2/ports.conf
listen to port 80 to 8080
nano /etc/apache2/sites-enabled/000-default.conf
listen to port 80 to 8080
systemctl restart apache2
#Setting up Varnish to listen to port 80
nano /etc/default/varnish
Scroll and locate the attribute ‘DAEMON_OPTS’. Be sure to change the port from 6081 to port 80
#If you check the /etc/varnish/default.vcl file, you should get the output shown below.
nano /etc/varnish/default.vcl
#Lastly, we need to edit the /lib/systemd/system/varnish.service and modify the port in ExecStart directive from port 6081 to 80.
nano /lib/systemd/system/varnish.service
Locate the ExecStart directive and change the port from port 6081 to 80.
systemctl restart apache2
systemctl daemon-reload
systemctl restart varnish
#Testing the Configuration
curl -I server_IP

How to Beautifully Formatted Archives by Month Separated by Year

Are you looking for a way to display a beautifully formatted archives list of months separated by year? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display formatted archives by month separated by year in WordPress.

Instructions:

All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

functionwp_custom_archive($args= '') {
    global$wpdb, $wp_locale;
    $defaults= array(
        'limit'=> '',
        'format'=> 'html', 'before'=> '',
        'after'=> '', 'show_post_count'=> false,
        'echo'=> 1
    );
    $r= wp_parse_args( $args, $defaults);
    extract( $r, EXTR_SKIP );
    if( ''!= $limit) {
        $limit= absint($limit);
        $limit= ' LIMIT '.$limit;
    }
    // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
    $archive_date_format_over_ride= 0;
    // options for daily archive (only if you over-ride the general date format)
    $archive_day_date_format= 'Y/m/d';
    // options for weekly archive (only if you over-ride the general date format)
    $archive_week_start_date_format= 'Y/m/d';
    $archive_week_end_date_format= 'Y/m/d';
    if( !$archive_date_format_over_ride) {
        $archive_day_date_format= get_option('date_format');
        $archive_week_start_date_format= get_option('date_format');
        $archive_week_end_date_format= get_option('date_format');
    }
    //filters
    $where= apply_filters('customarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r);
    $join= apply_filters('customarchives_join', "", $r);

    $output= '

;

        $query= "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";
        $key= md5($query);
        $cache= wp_cache_get( 'wp_custom_archive', 'general');
        if( !isset( $cache[ $key] ) ) {
            $arcresults= $wpdb->get_results($query);
            $cache[ $key] = $arcresults;
            wp_cache_set( 'wp_custom_archive', $cache, 'general');
        } else{
            $arcresults= $cache[ $key];
        }
        if( $arcresults) {
            $afterafter= $after;
            foreach( (array) $arcresultsas$arcresult) {
                $url= get_month_link( $arcresult->year, $arcresult->month );
                /* translators: 1: month name, 2: 4-digit year */
                $text= sprintf(__('%s'), $wp_locale->get_month($arcresult->month));

                $year_text= sprintf('

  • %d

, $arcresult->year);

                if( $show_post_count)
                    $after= ' ('.$arcresult->posts.')'. $afterafter;
                $output.= ( $arcresult->year != $temp_year) ? $year_text: '';
                $output.= get_archives_link($url, $text, $format, $before, $after);
                $temp_year= $arcresult->year;
            }
        }

    $output.= '

;

    if( $echo)
        echo$output;
    else
        return$output;
}
Add this snippet in your index.php file or any other template file where you want to display the formatted archives.

WordPress Enqueue Custom Fonts

/** Custom Fonts

function enqueue_custom_fonts(){
if (!is_admin()) {
wp_register_style(‘source_sans_pro’, ‘https://fonst.googleapis.com/’):
wp_register_style(‘nunito’, ‘https://fonst.google.com/’);

wp_enqueue_style(‘source_sans_pro’);
wp_enqueue_style(‘nunito’);

}

}
add_action (‘wp_enqueue_scripts’, ‘enqueue_custom_fonts’);

Free Web Hosting