CodePen

A shortcode for including CodePen embeds on your website

This will load the CodePen embed script everytime a CodePen shortcode has been used.

Usage

Global config

This shortcodes supports global configs that can be loaded from the Sites’ params object. user, editable and preview should be set and will act as a default. script_src can be used to load the embed script from a custom source instead of https://production-assets.codepen.io/assets/embed/ei.js

In the config.toml or config.yaml global values for the following variables can be set:

YAML config

params:
  kg_shortcodes:
    codepen:
      user: "kevingimbel"
      editable: true
      preview: true
      script_src: "/codepen.js"

TOML config

[params.kg_shortcodes.codepen]
user = "kevingimbel"
editable = true
preview = true
script_src = "/codepen.js"

Parameters

The CodePen shortcode takes the following arguments.

ArgumentDefault ValueValuesDescription
height256NumberHeight of the embedded iFrame
themedarkStringThe theme which will be used
resulthtml,resultComma separated list. Any of css, js, html, resultThe tabs which will be shown in the embed by default
userStringBooleanThe user to which this Pen belongs
editableSeitenkonfigurationBooleanDefines if the CodePen is editable by the user
previewSeitenkonfigurationBooleanDefines if the CodePen has “Run Pen” button or loads by default
slug-CodePen Slug (alphanumeric)The Slug of the Pen
title-StringThe title of the pen, shown if the embed can’t be loaded

Example Usage

Minimal options

{{% codepen slug="78d261a36ecded2b75d5260cb7056fce" title="An example embed" %}}

All options

{{% codepen slug="78d261a36ecded2b75d5260cb7056fce" title="An example embed" height="300" theme="light" result="css,js" user="ausername" editable="false" preview="false" %}}

Live Example

The CodePen shortcode is used on my private site, for example in the article “CSS Custom Properties and a new look”.