BT SVG Viewer
Embed large SVG diagrams in WordPress with zoom, pan, center, and authoring tools. Recent releases add a visual preset editor, icon-based controls, deeper shortcode options, and configurable button colors.
Contents
- Contents
- Installation
- Quick Start
- Shortcode Reference
-
controls_buttonsCheat Sheet
-
- Admin Preset Editor
- Location
- Fields
- Preview Pane
- Preset Shortcodes
- Defaults Tab
- Using Presets in Posts/Pages
- Preview Workflow
- Examples
- Styling (CSS Hooks)
- Tips & Troubleshooting
- SVG Preparation
- Common Issues
- Debugging
- Changelog Highlights (1.1.0)
- License & Credits
Installation
-
Unzip the plugin archive
- Download bt-svg-viewer.zip.
- Unzip it locally; you will get a folder named
bt-svg-viewer.
-
Upload the plugin
- Copy the entire
bt-svg-viewerfolder into your WordPress installation at/wp-content/plugins/.
- Copy the entire
-
Activate
- In the WordPress admin, navigate to Plugins and click Activate on ???BT SVG Viewer???.
Quick Start
[svg_viewer src="/wp-content/uploads/diagrams/system-map.svg"]
- Place the shortcode in a classic editor, Gutenberg shortcode block, or template.
- The SVG renders with default height (600px), zoom controls, pan/scroll behaviour, keyboard shortcuts, and responsive layout. Zoom buttons now gray out at the minimum/maximum zoom to make the limits obvious to visitors.
Shortcode Reference
| Attribute | Type | Default | Description |
|---|---|---|---|
src |
string (required) | ??? | SVG URL. Supports absolute URLs, /absolute/path.svg, or relative to the uploads directory. |
height |
string | 600px |
CSS height of the viewer. Accepts px, vh, %, etc. |
class |
string | ??? | Additional class appended to the wrapper. |
zoom |
number | 100 |
Initial zoom percentage. |
min_zoom |
number | 25 |
Minimum zoom percentage allowed. |
max_zoom |
number | 800 |
Maximum zoom percentage allowed. |
zoom_step |
number | 10 |
Increment used by buttons/keyboard shortcuts. |
initial_zoom |
number | ??? | Alias captured when presets save the preview state. Overrides zoom if present. |
pan / pan_mode
|
scroll or drag
|
scroll |
Toggle between scroll-wheel panning and click-drag panning. Drag is enforced when zoom modes require it. |
zoom_mode / zoom_behavior / zoom_interaction
|
super_scroll / scroll / click
|
super_scroll |
Choose how wheel and modifier gestures zoom: Cmd/Ctrl + wheel (super_scroll), every wheel (scroll), or Cmd/Ctrl-click & Alt-click (click). |
center_x / center_y
|
number | ??? | Manual center point in SVG units. Defaults to viewBox center. |
show_coords |
boolean | false |
Appends ???Copy Center??? button for debugging coordinate values. |
controls_position |
top/bottom/left/right
|
top |
Placement of the entire control group. |
controls_buttons |
string | both |
Comma-delimited mode/align/button list. See table below (supports slider). |
title |
string | ??? | Optional heading above the viewer. HTML allowed. |
caption |
string | ??? | Optional caption below the viewer. HTML allowed. |
button_fill / button_background / button_bg
|
color string | theme default (#0073aa) |
Button background color. Aliases exist for backwards compatibility (all map to button_fill). |
button_border |
color string | matches fill | Outline color for buttons. Blank inherits the fill color. |
button_foreground / button_fg
|
color string | #ffffff |
Text and icon color for buttons. Blank uses the default. |
id |
number | ??? | Reference a saved preset (admin). Inline attributes override preset values. |
Changing the interaction defaults automatically inserts a helper caption (e.g. ???Cmd/Ctrl-click to zoom in??????) above your custom caption so visitors know the gesture.
controls_buttons Cheat Sheet
controls_buttons="MODE,ALIGNMENT,BUTTON_1,BUTTON_2,..."
Mode keywords (optional):
-
both(default) icontextcompactlabels_on_hoverminimal-
hidden/none
Alignment keywords (optional, anywhere in list):
alignleftaligncenteralignright
Additional keywords:
-
slider??? replaces zoom buttons with a live-updating range input. Combine withicon/text/bothfor layout. Usecustom:slider,zoom_in,zoom_outto show both slider and buttons.
Button names (pick any order):
-
zoom_in,zoom_out,reset,center,coords(coords button only renders ifshow_coords="true")
Example:
[svg_viewer
src="/uploads/system-map.svg"
controls_position="right"
controls_buttons="slider,icon,aligncenter,reset,center"
]
Admin Preset Editor
Location
WordPress Dashboard ??? BT SVG Viewer ??? Presets
Fields
| Field | Description |
|---|---|
| SVG Source URL | Choose or upload an SVG from the media library. Required before preview loads. |
| Viewer Height | Same as shortcode height. |
| Zoom Settings | Minimum, maximum, step, and initial zoom percentages. |
| Center Coordinates | Override auto centering with explicit center_x/center_y. |
| Controls Position | Dropdown for top, bottom, left, right. |
| Controls Buttons/Layout | Text field following the MODE,ALIGN,buttons??? pattern described above. |
| Button Colors | Three color pickers for fill, border, and foreground (text/icon) colors. |
| Title & Caption | Optional, displayed above/below the viewer wrapper. |
Preview Pane
- Load / Refresh Preview: Injects the SVG using the current field values.
- Use Current View for Initial State: Captures the visible zoom level and center point from the preview and writes them back into the form (ideal for fine-tuning coordinates visually).
-
Copy Center: When
show_coordsis enabled, the button copies coordinates to the clipboard. - Zoom controls in the preview (and front end) now snap to their minimum/maximum, disable the corresponding buttons, and keep your pointer-focused zoom locked to the selected point???what you see in the preview is exactly what site visitors experience.
Preset Shortcodes
- At the top of the preset editor and in the presets list table you???ll find a copy-ready snippet in the form of
[svg_viewer id="123"]. - Click Copy to put the shortcode on the clipboard without selecting manually.
Defaults Tab
- Visit BT SVG Viewer ??? Presets ??? Defaults to seed the fields used when creating a new preset.
- The panel now includes Enable asset cache busting for debugging, which appends a time-based suffix to scripts and styles. It is automatically active on hosts that start with
dev.orwptest.and can be toggled manually when you need to defeat browser caching.
Using Presets in Posts/Pages
-
Create or edit a preset as described above.
-
Copy the generated shortcode (
[svg_viewer id="123"]). -
Paste into:
- Classic editor (Visual tab: use Shortcode block or paste directly).
- Block editor (Shortcode block or HTML block).
- Template files via
do_shortcode().
-
Override on a per-use basis if needed:
[svg_viewer id="123" controls_buttons="icon,alignright,zoom_in,zoom_out"]
Preview Workflow
- Load / Refresh Preview once the SVG path is entered.
- Drag or scroll the SVG to the desired default view.
- Use Current View for Initial State to stash those coordinates/zoom.
- Optionally toggle
show_coordsto display the current x/y values of the viewport center. - Save/publish the preset and test the shortcode on the front end.
Examples
[svg_viewer src="/uploads/floorplan.svg"]
[svg_viewer
src="/uploads/system-map.svg"
height="100vh"
controls_position="bottom"
controls_buttons="compact,aligncenter,zoom_in,zoom_out,reset,center"
zoom="175"
min_zoom="50"
max_zoom="400"
]
[svg_viewer
id="42"
controls_buttons="custom:slider,zoom_in,zoom_out,reset"
]
[svg_viewer
src="/uploads/mind-map.svg"
show_coords="true"
controls_buttons="icon,alignleft,zoom_in,zoom_out,reset,center,coords"
]
[svg_viewer
src="/uploads/campus-map.svg"
button_bg="#2f855a"
button_border="#22543d"
button_fg="#ffffff"
controls_buttons="both,aligncenter,zoom_in,zoom_out,reset,center"
]
Styling (CSS Hooks)
Wrapper classes added by the plugin:
-
.bt-svg-viewer-wrapper??? outer container -
.bt-svg-viewer-main??? wraps controls and SVG container -
.svg-controls??? control bar .controls-position-{top|bottom|left|right}.controls-mode-{icon|text|both|compact|labels-on-hover|minimal}.controls-align-{alignleft|aligncenter|alignright}-
.bt-svg-viewer-btn,.btn-icon,.btn-text -
.svg-container,.svg-viewport,.coord-output,.zoom-display -
.zoom-slider-wrapper,.zoom-slider
Button colors are powered by CSS custom properties on the wrapper. Shortcode attributes and preset color pickers set these values, but you can override them manually:
.bt-svg-viewer-wrapper {
--bt-svg-viewer-button-fill: #1d4ed8;
--bt-svg-viewer-button-border: #1d4ed8;
--bt-svg-viewer-button-hover: #1e40af;
--bt-svg-viewer-button-text: #ffffff;
--bt-svg-viewer-slider-width: 240px; /* optional: tweak slider width */
}Example overrides:
.bt-svg-viewer-wrapper.custom-map {
border-radius: 12px;
overflow: hidden;
}
.bt-svg-viewer-wrapper.custom-map .svg-controls {
background: #111;
color: #fff;
gap: 6px;
}
.bt-svg-viewer-wrapper.custom-map .bt-svg-viewer-btn {
background: rgba(255,255,255,0.1);
border: 1px solid rgba(255,255,255,0.3);
}
.bt-svg-viewer-wrapper.custom-map .bt-svg-viewer-btn:hover {
background: rgba(255,255,255,0.25);
}Tips & Troubleshooting
SVG Preparation
- Remove hard-coded width/height if possible; rely on
viewBox. - Ensure the SVG renders correctly when opened directly in a browser.
- Compress large SVGs to keep loading snappy.
Common Issues
- Blank viewer: check for 404 on the SVG path, confirm the file is accessible without authentication.
-
Scaling looks wrong: verify the SVG has an accurate
viewBox. -
Controls disappear: check
controls_buttonsforhiddenor empty button list. -
Clipboard errors: Some browsers require user interaction for
Copy Center; the plugin falls back to a prompt.
Debugging
- Toggle
show_coords="true"or inspectwindow.svgViewerInstances['viewer-id']to troubleshoot zoom, center, or scroll behaviour. - Use the Defaults tab???s Enable asset cache busting for debugging switch if your browser clings to stale copies of the viewer script or styles.
Changelog Highlights (1.1.0)
-
Pan/Zoom Interaction Modes: Shortcode and presets can now request
pan_mode="drag"orzoom_mode="scroll"/click", with the front end auto-explaining gesture hints to visitors. - Smooth Cursor-Focused Zoom: Wheel, slider, and modifier-click zoom animate between stops and keep the point under the pointer locked in place.
- Responsive Drag Panning: Dragging now tracks 1:1 with the pointer and ignores stray wheel events so diagonal swipes stay fluid.
-
Dev-Friendly Cache Busting: The Defaults tab adds an ???Enable asset cache busting??? switch (also auto-enabled for
dev.*andwptest.*hosts) to force fresh JS/CSS while testing.
Full changelog lives in the repository???s CHANGELOG.md.
License & Credits
- License: GPL-2.0 (same as WordPress).
- Built to make large interactive diagrams pleasant to navigate inside WordPress.