cables DocumentationHow To UseWorking with filesKeyboard ShortcutsUser Interface WalkthroughBeginner TutorialBeginner 1: Drawing A CircleBeginner 2: TransformationsBeginner 3: ColorMore TransformationsTimeline Keyframe AnimationIntermediateImage CompositionsPost-Processing 3D ScenesExporting And EmbeddingHow to serve files externally and fix CORS headersExporting PatchesExport using the cables command line interfaceExport via IframeExport creating a standalone executableExport to github (pages)Export and deploy to netlifyExport full PatchHTML ExportExternal triggers / functionsUsing variablesPreviewing / uploading exported cables patchesExamples for EmbeddingImporting patchesBackupsPermissionsUsersPatchesTeamsOpsMultiplayerPatchlistsCoding OpsUsing Op AttachmentsGeneral op/Port CallbacksPortsMultiPortsArray PortsBoolean portsInteger Number PortsObject PortsString portsTrigger PortsFloating Point Number PortsGUI/UI attributesHello Op - Part 1LibrariesDeveloping OpsRenaming / Creating a new versionCreating Viz OpsGuidelinesObject PortsPatching Ops / SubPatchOpsWriting ShadersWeb Audio Op DevelopmentDeveloping CablesRepositoriesSet up local environmentScriptsHow to work with forksGenerated DocumentationUsing standalone to develop cablesCables StandaloneGeneralCoding OpsSharing opsUsing NPMImport/ExportStandalone - FAQLightingLightsShadowsWorking With AudioBasic Audio SetupWorking with EffectsReal-Time Audio Analyzation & Audio VisualizationOffline Audio Visualization & AnalyzationCommunicationCables APIOptimizing Performance In PatchesTools for debugging your patchHow to optimize cables patches with the Performance opHow to optimize cables patches with the ProfilerCommon pitfalls with the "usual suspects"Optimizing arraysDebugging Shaders with ShaderInfoFAQAudio in web browsersHow to make demoscene demos with cables.glEmbeddingHow to integrate my cables patch into my CMS (webflow/wix/squarespace/...)?Cables and WordPressHow to remove grey rectangles on touch (mobile)?Why doesn't the DownloadTexture op work on iOS?How to disable page scrolling on mobile?Mobile tippsHow to run exported patches on your local machineTransparent CanvasFeatures and SupportHow to contribute code to cablesWill there be support for (animated) GIFs?Can i use a website as a texture?Screenshots and Video recordingHow to report a bug in cablesHow can I share a patch to get help?How can I support cables?Video playback in cablesGeneral questionsWhat is dev.cables.glHTML And CSS In CablesJavascript Frameworkscordova / phonegapelectronreactvuejsLicenses and paymentWhat license do i need to use cables?Will I have to pay for it in the future?How is my work licensed when using cables?Does cables support midi and OSC?Patch PermissionsMy User Profile & Social MediaShadertoyCables at schools and universitiesTechnical questionsWebGL1 and WebGL2

Cables and WordPress

You can show exported cables patches on a WordPress site with a small shortcode that embeds them in an iframe. Everything is loaded from your own WordPress installation, nothing is requested from cables.gl.

Exporting your patch

Export your patch to HTML and unzip the downloaded file.

Where to put the patch

Upload the unzipped export into the uploads folder of your WordPress, e.g. via SFTP:

wp-content/uploads/cables/my-patch/index.html
wp-content/uploads/cables/my-patch/js/...
wp-content/uploads/cables/my-patch/assets/...
  • Every patch gets its own folder, the index.html of the export has to be directly inside of it.
  • Use only lowercase letters, numbers and dashes for the folder name (my-patch, not My Patch), the folder name is what you use in the shortcode.
  • The uploads folder is publicly accessible and is not touched by WordPress-, theme- or plugin-updates.
  • Only upload the files of the export, there should never be any .php files in these folders.

Installing the shortcode

Copy the following code to the end of the functions.php of your (child-)theme:

function cables_patch_shortcode( $atts ) {
    $folder = 'cables/';

    $atts = shortcode_atts( array(
        'patch' => '',
    ), $atts, 'cables' );

    $name = sanitize_title( $atts['patch'] );
    $up   = wp_upload_dir();
    $path = trailingslashit( $up['basedir'] ) . $folder . $name . '/';
    $base = trailingslashit( $up['baseurl'] ) . $folder . $name . '/';
    if ( ! $name || ! file_exists( $path . 'index.html' ) ) {
        return current_user_can( 'manage_options' ) ? '<p>cables: patch "' . esc_html( $name ) . '" not found.</p>' : '';
    }

    if ( ! wp_style_is( 'cables-patch' ) ) {
        wp_register_style( 'cables-patch', false );
        wp_enqueue_style( 'cables-patch' );
        wp_add_inline_style( 'cables-patch', 'iframe:where(.cables-patch){display:block;width:100%;aspect-ratio:16/9;border:0;}' );
    }

    return sprintf(
        '<iframe class="cables-patch" src="%s" allow="fullscreen; autoplay; xr-spatial-tracking; camera; microphone; gyroscope; accelerometer; midi" allowfullscreen loading="lazy"></iframe>',
        esc_url( $base . 'index.html' )
    );
}
add_shortcode( 'cables', 'cables_patch_shortcode' );

Use a child theme if you can, changes to the functions.php of a regular theme are lost when the theme is updated.

Usage

Add a "Shortcode"-block in the editor (or just type it into the classic editor or a widget) and enter:

[cables patch="my-patch"]

This shows the patch in an iframe, with a width of 100% and an aspect ratio of 16/9 by default. You can use as many patches on one page as you like.

If you are logged in as an administrator, a message will be shown in place of the patch in case the folder or its index.html can not be found.

Using the shortcode in a theme template

<?php echo do_shortcode( '[cables patch="my-patch"]' ); ?>

Styling

All styling is done in CSS, e.g. in "Appearance > Customize > Additional CSS".

The iframe has the class cables-patch, the default size can be overwritten like this:

.cables-patch {
  width: 100%;
  aspect-ratio: 4 / 3;
}

Troubleshooting

  • Check if the exported patch works on its own by opening https://yoursite/wp-content/uploads/cables/my-patch/index.html in your browser.
  • If the iframe shows a "not found" page, check the folder structure of your upload, the index.html has to be directly inside the patch folder.

Found a problem? Edit this file on github and contribute to cables!