Using conditional functions in WordPress

When creating custom themes for WordPress, often you’ll need to load different styles or scripts for a specific page template, or for the home page. One way to do it is to create a different header or footer that includes those files, and then load the custom header or footer from the page template:


A better way to do it is to use conditional functions in your theme’s functions.php file. You can test for a specific page template, or for the front page. This will help you keep your template files clean and reduce code duplication. (Keep things DRY: don’t repeat yourself.)

Here’s a handy way to load different styles depending on the page template:

// your custom page styles
if (is_page_template('page-custom.php')) {
  wp_enqueue_style( 'custom-styles', get_template_directory_uri() . '/css/custom.css', array(), '1.0.0' );

Load a JavaScript file in the footer only on the home page:

// front page JS
if (is_front_page()) {
   wp_enqueue_script( 'custom_js', get_template_directory_uri() . '/js/custom-script.js', array(), '1.0.0', TRUE );

You can also use these functions within your template files such as header.php and footer.php, but you might as well put it in the functions.php file since you will be loading other scripts there. By keeping it all in one place, you can change things more easily down the road.

From the WordPress Code Reference:



Should you choose WordPress or Squarespace for your nonprofit website?

When you are planning a new web project, you will need to take into consideration the content management system (CMS) that powers the website. If you don’t know what a content management system is, at a basic level it is just software you use to edit the content on your website.

As a nonprofit, you have the task of finding a system that will provide all the features you need while fitting into your budget. In this post we will take a look at two popular web platforms, and discuss the advantages and drawbacks of each.

What are WordPress and Squarespace?

WordPress is an open-source CMS that you run and manage on your own web hosting account. A web designer or developer will create a custom theme or install an existing theme for you. The theme controls the design of the website. Plugins might be installed that add functionality to WordPress and your website.

Squarespace is an all-in-one platform that combines web hosting, design, and content management into one system. A designer will modify an existing template, or create a custom one using the developer platform. Most of the website functionality will be built-in to Squarespace, and some third party solutions may be required to fill in any gaps.

Why should I use WordPress?

WordPress can be a great choice for a nonprofit website. It’s widely supported, stable, and adaptable. The availability of high-quality themes can help provide a solid design foundation for the website, and completely custom themes can be built as well. Plugins for accepting donations, creating forms and event calendars bring additional functionality to the website.

WordPress also makes content management straightforward. It works well in a multi-author environment where more than one person is contributing to the website. Content can be version controlled, granting authors the ability to revert changes. The content editor is easy to use, and anyone familiar with word processing software will be able to use it without trouble.

Why should I choose Squarespace?

The Squarespace platform can also be a good choice for a nonprofit website. The available templates are well designed, helping you create a consistent experience across your website. The designs can be customized further using the Squarespace tools and by a web developer with knowledge of CSS, the web language used to style websites.

With other platforms such as WordPress, a web developer may spend more time modifying source code to create a custom design for your website. In general, Squarespace allows a web designer or developer to build a site faster, saving you money and getting your project live sooner.

What are the potential drawbacks to WordPress?

A common objection to WordPress relates to security. Because WordPress is a widely used platform, it can be a target for those that want to cause trouble. But much of the security concerns with WordPress can be accounted for with correct setup of the software and theme, careful use of plugins, and a secure hosting environment. It is recommend to use WordPress-specific hosting such as Nexcess or Pantheon. Other considerations with WordPress would be the need for ongoing software updates and the cost of any commercial plugin licenses.

What are the potential issues with Squarespace?

Squarespace does many things very well. However, you may find an occasion where you run into limitations of the platform. It doesn’t do everything, and it is more difficult to get around limitations than WordPress. There is no content versioning, which means it’s harder to see what has changed and more difficult to undo accidental changes. The media management tool is limited—you may find yourself uploading multiple copies of the same image for use on different pages. Sometimes the page editor can be a bit quirky.

So which one should I choose?

Ultimately, that decision will be driven by the specific needs of your project. Squarespace will get you up and running quickly, and likely for a lower cost, while WordPress will give you more flexibility in the long run. Things to keep in mind when planning a project are the initial design cost, any ongoing cost of hosting and maintenance, recurring software licensing fees, whether the system will meet your needs, and if the platform is flexible enough for changes and enhancements. Whatever you choose, there are ways to migrate at least some data from one to the other so you are not locked into a system. You can always make a change in the future, though you should expect any platform migration to be comparable to a new website project.


Is Squarespace right for your business website?

You probably have heard of Squarespace by now. It is a website platform that includes tools to design and build your website as well as built-in hosting and email. If you need to register a domain, Squarespace allows you to do that too. Email services are provided by Google G Suite (formerly Google Apps). If you have a business and need a website, it’s worth considering Squarespace as an option.

What type of business do you operate?

Depending on the nature of your business, Squarespace could be a good choice for your website. I find it works particularly well for:

  • Design, photography, or artist portfolio websites with many images
  • Small brochure-style informational websites with a few pages of static content and a blog or news section
  • Restaurants that can take advantage of the built-in menu templates and OpenTable integration
  • A small business just getting started

Website conversions to Squarespace

Recently, I have worked on projects converting older websites into a mobile-friendly format with Squarespace. Squarespace makes it relatively straightforward to import existing content and set up a new design. The development time on these projects is reduced thanks to well-designed templates that act as a starting point. There are a few general purpose themes that work well for a small business such as Bedford or Hayden. Content can be imported from WordPress or other formats.

When Squarespace may not be the right solution

If you maintain a website with a large amount of content and multiple content authors, it may be better to use a more traditional platform such as WordPress or Drupal. WordPress is designed for managing text content, includes a visual revision comparison tool out of the box, and functions well in an environment with multiple content authors.

While Squarespace works well for portfolio sites with a lot of imagery, the media management tools fall a little short. I find it easier to browse and reuse assets with the media library in WordPress.

If you need absolute control over your hosting environment, Squarespace will not be the right choice. It fills a niche for businesses that want an all-in-one platform and don’t need to maintain a web server.

The bottom line

Squarespace is definitely worth a look when you are considering your next online venture, or if you need to upgrade an existing site. It may help you trim your online marketing budget if you don’t need the extra flexibility that a traditional content management system would provide. Feel free to contact me for further recommendations.

Are you solving your client’s problems, or just showing off?

You may not know it, but your client hired you to solve a problem. They did not hire you just to build a website, make an app, or design a new logo. That may be part of the solution, but your first task is defining the problem. Is your client not getting new business from the website? Is an outdated design creating the wrong initial impression? Are technical issues causing the site to fall in search engine positioning? Do design flaws contribute to a lack of engagement and a high bounce rate?

Your client may be aware of some of the challenges, though they may not know how to access the Google Analytics account or if it is even installed. They may just have a vague idea that the website needs to be mobile-friendly, and that the current design looks out of date. Your role as the professional is to help your client define the issues being addressed and what technical and design solutions will be used to meet the project goals.

The web design and development industry is awash with tutorials and training designed at teaching you the latest techniques. Keeping up to date on the technology and trends is a great idea, but what often seems to be missing is the larger context. Instead, we are presented with an overwhelming amount of technical detail and the presumption that learning about it is worth our time. Some of those details are essential while much of it is not. If you focus on the technology alone, you might just forget the greater objective.

Years ago, Flash websites were the norm. Customers spent thousands of dollars on custom websites that were little more than online brochures with excessive animation. This was not a sustainable approach. The website content was closed off in a plugin, unable to be indexed by search engines. And the content was largely inaccessible to the keyboard and users with disabilities. The Flash plugin itself ultimately became a security risk. Better alternatives arose to handle desktop and mobile applications.

At one point, Flash was the best choice for building interactive applications and displaying videos. But Flash was never the best choice to reproduce what could be a standard HTML website. It was used to add heavy interface animations to otherwise simple websites. Too often this was an excuse for web designers and developers to showcase technical knowledge and was not serving the long-term interests of their customers.

Today’s applications are based on standard web technologies that are not going anywhere (HTML, CSS, and JavaScript on the front-end). Even so, you may still find an animation-heavy website that looks like a throwback to the Flash heyday. Recent commercial WordPress themes often suffer from this issue. They are designed for the purpose of selling the theme. It may look exciting, but at the expense of slow load times and a poor user experience.

Taking a step back to recall the reason why you are learning a new technology will help both you and your clients. Remember the problem you are solving, and think about the end users. Ask yourself if you are contributing value or just using the project as an excuse to show off.

Proactive website maintenance

Keep your website updated

I've helped a number of clients over the years, building custom websites for their businesses and projects. Primarily, these sites have been built with ExpressionEngine or WordPress as the CMS. Too often there is a perception that one just builds the site, and then you're done for good. The reality is that building the website is only part of the process. Once the website is launched, you need to allow for time and money to keep the website updated. This means keeping the CMS updated, using security add-ons or plugins, configuring security at the application and server level, and monitoring the site for changes and anything unusual.

Should you do it yourself?

That depends. If you are comfortable configuring software and have some familiarity with the ins and outs of web hosting, then you may be able to handle things yourself. In most cases, no, you should not rely on yourself to keep things current and secure. Hopefully you have a good relationship with your web developer, and you rely on their guidance for this process. Yes, this costs extra money. If the cost of monthly maintenance is a concern, you should not be developing a custom website. Instead, use a commercial website platform. There are a few out there that will give you decent results if you want to do it yourself.

Why should I pay to keep my website updated?

Lately, I've seen some older installations of ExpressionEngine fall victim to tampering. The attacks were aimed primarily at WordPress and the damage was minimal. The fixes were straightforward and took a few hours to restore the sites to normal. The restoration involved ending the attack by blocking the attacker, removing malicious files, restoring user accounts, updating the core software and add-ons, and changing some setting at the server level. These attacks could have been much worse if not caught early on. In general, the cost of some proactive maintenance is less than the cost to fix a hacked website.

Website shelf life

The process of keeping your website up to date is an ongoing process, continuing until the next redesign or redevelopment. The website itself does have a shelf life. Technology changes. Current design trends change. You may reach a certain point where the site needs to be redesigned or reworked in some way. This may happen as your business evolves. In the meantime, minding the underlying software will help you keep the site up and running. Feel free to contact me for assistance.