wp-rdnyc/custom-functions.php

67 lines
2 KiB
PHP
Raw Normal View History

<?php
2021-07-28 22:51:24 -04:00
/**
* standard "page/multi-post index/listing" & "single-blog-post" header styles
*/
function get_page_multi_heading( $content_str = '' ) {
$class = 'fw-light text-gray-400 mb-4 border-bottom border-dashed border-spaceblue-600';
return '<h1 class="' . $class . '">' . $content_str . '</h1>';
}
function get_post_single_heading( $content_str = '' ) {
$class = 'fs-2 fw-600 mb-2';
return '<h2 class="' . $class . '">' . $content_str . '</h2>';
}
/**
2021-07-26 13:07:57 -04:00
* example inline SVG function atts array supported keys
*/
// array(
// 'div_class' => 'icon baseline', // or 'img logo' or something
// 'svg_class' => '',
// 'svg_title' => '',
// 'role_img' => false,
// 'aria_hidden' => true
// )
/**
* inline SVG function
* desired SVG must exist in ./dist/images,
* preferably by import in main.js and processing by webpack
*/
2021-07-26 13:07:57 -04:00
function inline_svg( $svg_name, $atts = array() ) {
// load atts or set defaults
extract(shortcode_atts(array(
'div_class' => '',
'svg_class' => '',
'svg_title' => '',
'svg_role_img' => false,
'svg_aria_hidden' => true,
), $atts));
// load initial svg content
2021-07-25 09:29:15 -04:00
$svg_content = file_get_contents( get_template_directory_uri() . '/dist/images/' . $svg_name . '.svg' );
// replace svg class
$svg_content = str_replace('{{class-placeholder}}', $svg_class, $svg_content);
// handle if role=img
2021-07-25 09:29:15 -04:00
$svg_content = $svg_role_img ? str_replace('<svg ', '<svg role="img" ', $svg_content) : $svg_content;
// handle if aria_hidden
2021-07-25 09:29:15 -04:00
$svg_content = $svg_aria_hidden ? str_replace('<svg ', '<svg aria-hidden="true" ', $svg_content) : $svg_content;
// handle svg title
2021-07-25 09:29:15 -04:00
$svg_title = $svg_title == '' ? '' : '<title>' . $svg_title . '</title>';
$svg_content = substr_replace($svg_content, $svg_title, strpos($svg_content,'>') + 1, 0);
// handle if div class
2021-07-25 09:44:34 -04:00
$svg_content = $div_class == '' ? $svg_content : '<div class="' . $div_class . '">' . $svg_content . '</div>';
// return assembled svg (or div>svg)
2021-07-25 09:44:34 -04:00
return $svg_content;
};
?>