Absolute Minimum for a Working WordPress Theme

Let’s say you are thinking about all the files that a typical WordPress theme contains and wondering what of that is actually necessary for your site to work. If you are in need of a very simple theme, say to display an images or few, you could quickly make it from scratch. Here is the start.

The minimum requirement for a WordPress theme to work are index.php and style.css files.

The style.css file sets the name of your theme which will be displayed in the dashboard. The format is this:

/*
Theme Name: My New Minimal Theme
*/

That’s it, we only enter the theme’s name. Please note the commenting, it is required. Below this part is where your style will be added.

The minimum of content for the index.php file is a loop in it’s simplest form:

<?php
  if ( have_posts() ) : while ( have_posts() ) : the_post();
   the_content();
  endwhile; endif;
?>

That’s it. You will be able to show the content of whatever page or post(s) are set to display as homepage.

Now we can easily build from there. To add a post title, the code should look like this:

<?php
  if ( have_posts() ) : while ( have_posts() ) : the_post();
   the_title();
   the_content();
  endwhile; endif;
?>

And so on… In the next post we’ll be adding navigation. And let’s see just how many lines of code it takes to make a simple, functional and responsive theme.

Varnish with Apache on Ubuntu 16.04

1.
In
/lib/systemd/system/varnish.service
and
/etc/default/varnish
set port to 80:

ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

and

DAEMON_OPTS="-a :80 \

2.
In
/etc/varnish/default.vcl
point to port 8080, where Apache will be serving content:

backend default {
.host = "127.0.0.1";
.port = "8080";
}

3.
Finally, change Apache’s default port 80 to 8080, in
/etc/apache2/sites-enabled/mysite.conf

To test:

GET -Used http://siteaddress.com

Inline Style in WordPress Caption Shortcode

Those 10px the [Caption] tag adds to the attachment div, likely breaking your style in the process, are fixed with the following. The style tag setting width has been commented out.

add_filter( 'img_caption_shortcode', 'cleaner_caption', 10, 3 );

function cleaner_caption( $output, $attr, $content ) {

	/* We're not worried abut captions in feeds, so just return the output here. */
	if ( is_feed() )
		return $output;

	/* Set up the default arguments. */
	$defaults = array(
		'id' => '',
		'align' => 'alignnone',
		'width' => '',
		'caption' => ''
	);

	/* Merge the defaults with user input. */
	$attr = shortcode_atts( $defaults, $attr );

	/* If the width is less than 1 or there is no caption, return the content wrapped between the < tags. */
	if ( 1 > $attr['width'] || empty( $attr['caption'] ) )
		return $content;

	/* Set up the attributes for the caption <div>. */
	$attributes = ( !empty( $attr['id'] ) ? ' id="' . esc_attr( $attr['id'] ) . '"' : '' );
	$attributes .= ' class="wp-caption ' . esc_attr( $attr['align'] ) . '"';
/*	$attributes .= ' style="width: ' . esc_attr( $attr['width'] ) . 'px"';   */

	/* Open the caption <div>. */
	$output = '<div' . $attributes .'>';

	/* Allow shortcodes for the content the caption was created for. */
	$output .= do_shortcode( $content );

	/* Append the caption text. */
	$output .= '

' . $attr['caption'] . '

'; /* Close the caption </div>. */ $output .= '</div>'; /* Return the formatted, clean caption. */ return $output; }

WordPress Automatic Update without FTP

Insert this line at the end of your wp-config.php file. This file is found in your site’s public root directory, sometimes called www, httpdocs or public_html.

define('FS_METHOD','direct');

This will allow your site to bypass all the permission and file ownership warnings and update your WordPress installation to the latest version.