mindkomm/theme-lib-content

Collection of content helper functions for WordPress themes

1.1.0 2019-06-13 09:11 UTC

This package is auto-updated.

Last update: 2024-10-13 21:50:34 UTC


README

A collection of content helper functions for WordPress themes.

Installation

You can install the package via Composer:

composer require mindkomm/theme-lib-content

Usage

The content filter

A content filter that you can use for text that is not the main content.

{{ post.custom_text|apply_filters('content') }}

Functions

strip_control_characters

Strips out forbidden Control Characters that came from copy-pasting text into WYSIWYG editor.

You can’t see these Control Characters when you look at the text, yet they can still lead to unexpected behavior.

strip_control_characters( string $text )

Returns: string The filtered text.

lines_to_array

Turns each line of a text into an array.

lines_to_array( string $string )

Returns: array

Twig

<ul>
{% for line in multiline_text|lines_to_array %}
    <li>{{ line }}</li>
{% endfor %}
</ul>

truncate_close

Truncates a text close a certain number of characters.

This function doesn’t cut off words, but only adds the words that still fit into the maximum width.

truncate_close( string $string, int $desired_width = 200, string $more = &nbsp;&hellip; )

Returns: string Truncated string.

Twig

{{ post.content|truncate_close }}

gender

Gets string by gender.

Yes, for now, this supports only male and female genders.

gender( string $male, string $female, string $gender, array $female_identifiers = [] )

Returns: string

PHP

<?php
echo gender( 'Schreiner', 'Schreinerin', $post->gender );

Twig

{{ gender( 'Schreiner', 'Schreinerin', post.gender ) }}

Support

This is a library that we use at MIND to develop WordPress themes. You’re free to use it, but currently, we don’t provide any support.