Created
March 21, 2018 12:21
-
-
Save JayGeorge/83b4305c3eb742b62a1f8f62326868c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* GROUP ALT TEXT FALLBACK | |
=================================================== */ | |
class PerchTemplateFilter_alt_text_fallback extends PerchTemplateFilter | |
{ | |
/* Notes... | |
- If no alt text is filled in, use the file name as a fallback so it's not blank | |
- e.g. alt="<perch:if exists="alt"><perch:content type="text" id="alt"/><perch:else /><perch:content id="image" filter="convert-filename-to-alt-text"/></perch:if>" | |
*/ | |
public function filterBeforeProcessing($value, $valueIsMarkup = false) | |
{ | |
$value = preg_replace( | |
array('/-[1-9][.].*/','/[.].*/'), | |
array('',''), | |
$value | |
); | |
$value = str_replace( | |
array('/perch/resources/', '-'), | |
array('', ' '), | |
$value | |
); | |
return ucfirst($value); | |
} | |
} | |
PerchSystem::register_template_filter('alt-text-fallback', 'PerchTemplateFilter_alt_text_fallback'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handy if you tend to use descriptive text for your file names, this saves you some work adding alternative text for all your images. Drop this in
filters.php
.See Perch's Filter documentation for more information.