# codepen-embed-block/trunk/src/utils/getPenHTML.js

CodePen Embed Block, version trunk. 70 lines.

- Page: https://pluginprobe.com/plugins/codepen-embed-block/trunk/code/src/utils/getPenHTML.js
- Raw: https://pluginprobe.com/plugins/codepen-embed-block/trunk/raw/src/utils/getPenHTML.js
- Modified: 2025-06-25T20:20:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/codepen-embed-block/trunk/code/src/utils/getPenHTML.js#L10-L20`.

```javascript
/**
 * WordPress dependencies
 */
import { __ } from "@wordpress/i18n";

/**
 * Internal dependencies
 */
import getNewEditorCheck from "./getNewEditorCheck";

export default function getPenHTML(attributes) {
  const {
    penID,
    penTheme,
    penHeight,
    penURL,
    penType,
    clickToLoad,
    editable,
    isEditorURL,
  } = attributes;

  if (penID === null && penURL === "") {
    return null;
  }

  if (null === penID) {
    return (
      <p className="codepen error" style={{ textAlign: "center" }}>
        {__("The pen URL is invalid.")}
      </p>
    );
  }

  let embedUrlPrefix = "//codepen.io/anon/embed";
  if (isEditorURL || getNewEditorCheck(penURL)) {
    embedUrlPrefix = "//codepen.io/editor/anon/embed";
  }
  if (clickToLoad) {
    embedUrlPrefix += "/preview";
  }

  let src = `${embedUrlPrefix}/${penID}?height=${penHeight}&theme-id=${penTheme}&slug-hash=${penID}&default-tab=${penType}`;

  if (editable) {
    src += "&editable=true";
  }

  return (
    <div className="cp_embed_wrapper">
      <iframe
        id={`cp_embed_${penID}`}
        src={src}
        height={penHeight}
        scrolling="no"
        frameborder="0"
        allowTransparency={true}
        allowFullScreen={true}
        allowPaymentRequest="true"
        name={`CodePen Embed ${penID}`}
        title={`CodePen Embed ${penID}`}
        className={"cp_embed_iframe"}
        style={{ width: "100%", overflow: "hidden" }}
      >
        CodePen Embed Fallback
      </iframe>
    </div>
  );
}

```
