WP SVG Helpers makes it easy to inline SVG files into any WordPress project.
Supported by 10up.
- Upload the entire
/wp-svg-helpers
directory to the/wp-content/plugins/
directory. - Activate WP SVG Helpers through the Plugins menu in WordPress.
The SVG file path for the activated theme can be set via a setting through the Settings > Media menu in WordPress. By default, the path is set to assets/svg/dist/
, but it can be easily changed. Follow these steps to change the file path setting:
- Navigate to the Settings > Media menu in WordPress.
- Look for the new section in the WordPress Media Settings Screen titled SVG Helpers.
- Enter the correct path to your theme's SVG files in the input field.
- Click Save Changes.
WP SVG Helpers has two template tags for use in a theme.
For an inlined SVG file, use:
<?php inline_svg( 'name-of-svg' ); ?>
For a button with an SVG file, use:
<?php svg_button( 'name-of-svg', 'Button Title', 'location', 'class', 'a11y' ); ?>
The SVG file location is optional for buttons, but it can be easily set to either right
or left
. If the location is not provided, the SVG file will be located on the left by default.
The class
is the css class for the button and a11y
allowes for developer defined accessibility attributes.
The CSS class for buttons can be easily filtered via a custom function filtering wpsvg_button_class
. To filter the button class, use:
<?php
function my_button_filter( $classes ) {
$classes[] = 'your-button-class';
return $classes;
}
add_filter( 'wpsvg_button_class', 'my_button_filter' );
?>
Accessibility attributes can be easily defined as a string, as such:
<?php svg_button( 'name-of-svg', 'Button Title', 'location', 'class', 'aria-pressed=false' ); ?>
The Roadmap aims to outline future features.
- Addition of JavaScript helper functions.