Occasional thoughts.

Set the default Parent Page and Template in Wordpress using php

On a Wordpress site I have users who need to add content to a particular section of the site and nowhere else. To make editing as simple as possible, I want to set the Parent page and Template automatically when users with a certain role are adding a new page. Add these two functions to your theme's functions.php file.

Conditional Email Recipients with Webform

Building on an earlier post about multiple email recipients, we are now going to see how to add multiple recipients to a single email, when webform is setup to send emails to multiple people. Here is an example setup. Two people within the organization are receiving the email submission and the visitor is receiving a confirmation message. The confirmation uses a different template from the internal messages.

Shareable with Open Graph and Twitter Cards

When sharing content across social media platforms, Open Graph and Twitter Card Tags (Twitter's extension of Open Graph) can be used to optimize how information is displayed.

Checking the Workbench Moderation State with Rules

Setting up Rules to trigger when a moderation state is changed was not working as expected. I was trying to check the condition for Node: "Content's current moderation state" and "Content's previous moderation state." I want to send an email to certain users when content is moved from Draft to Needs Review. Using an event trigger of "After moderation transition," I need to check when the previous moderation state is Draft and the current is Needs Review.

URL formatting with Regex for Drupal and CKEDITOR

If you list a URL without the protocol and it is processed by the "Convert URLs into links" input filter, "http" will be automatically prepended, regardless of the site being setup for https. Since you don't know what the protocol should be without testing, this is an acceptable fallback. Since the site I am working on uses https, every page that includes the site address without the protocol is being flagged as a having a broken link. If it was a link to an external site I would not be as concerned, as these occasionally change anyways, but a link within a site should be correct.

Multipe Email Recipients with Webform

Through the Drupal Webform configuration you can specify multiple To addresses but not Cc or Bcc. Webform works by sending a separate email to each To address. For a single email to multiple people, you can add THEME_webform_mail_headers() to your template.php as shown below.

You also have access to $node (node object for the webform) and $submission (webform submission of the user) if you need to add additional processing.

Dropping Support for Old Browsers

For a long time I have tried to hold onto users who are reluctant or unable to upgrade their browser, at the cost of not supporting modern browsers to the extent that they should be supported. This has been an unfortunate case of certain industries struggling to catch up and still relying on older technology. As CSS3 makes many interface elements easier to create, you need to decide if you prefer to advance technology or grasp at the past. Depending on the audience you are developing for, you may not be able to write-off older browsers as quickly as you would like.

Responsive Font Sizing

For years I have used "font-size: 62.5%" (10px) as my base font size. Text sizing was easy, 1.2em for 12px, 1.8em for 18px. Over time I have seen an increase in overall font size usage. I have been spending considerable time converting a desktop theme to be responsive. By switching to a base font-size of 100% (16px), the small increase in size makes readability much better and less elements need to be adjusted so there is also a decrease in font-size declarations.

Creating a Calendar in Drupal with Field Collection

The Field Collection module is a popular choice for creating an entity with multiple attached fields. This allows you to have multiple sets of the same fields on a single page. This is helpful if you would like to have an Event node with multiple dates, which may repeat at different times. For example, if you have a seminar that repeats monthly but times alternate between morning and evening.

Subscribe to my articles