Git Product home page Git Product logo

syllable-hyphenator's Introduction

Syllable Hyphenator

Build Status Inactively Maintained

Screenshot of two WordPress pages. Normal on the left, hyphenated on the right

Server-side hyphenation for WordPress with Syllable library. It works by inserting ­ or "soft hyphen" characters to your strings so browsers will hyphenate the words correctly for you.

Compatiblity

  • PHP 7 +
  • WordPress 5.0 +
  • (Optional) Timber 1.10.0 +
  • (Optional) Polylang

Installation

  1. Download latest version on the Releases page.
  2. Upload plugin on the WordPress plugin admin page.
  3. Activate plugin.
  4. See section below on how to use the plugin in your theme

Usage

You can use the syllable_hyphenate WordPress filter to hyphenate text.

echo '<h1>' . apply_filters('syllable_hyphenate', get_the_title($post)) . '</h1>';

If you are using Timber, you can also use the hyphenate Twig filter,

<h1>{{ post.title | hyphenate }}</h1>

You can use the syllable_hyphenate_html filter to hyphenate a HTML string. For example, let's say you want to hyphenate output of Heading Gutenberg blocks. You can do it with the following code:

add_filter('render_block', function ($content, $block) {
    if ($block['blockName'] === 'core/heading') {
        $content = apply_filters('syllable_hyphenate_html', $content);
    }
    return $content;
}, 10, 2);

Filters

Minimum word length

syllable_hyphenator_min_word_length

By default, minimum word length for hyphenation is set to 12 characters. This prevents awkward hyphenation of very short words.

add_filter('syllable_hyphenator_min_word_length', function () {
  return 6;
});

WordPress locale

syllable_hyphenator_wp_locale

Language used for hyphenation. By default this is the language specified in the WordPress settings page. This can be overridden using this filter. The locale should be in WordPress locale format, for example en_US.

add_filter('syllable_hyphenator_wp_locale', function () {
  return 'en_US';
});

Current language

syllable_hyphenator_current_locale

This overrides the WordPress language. This is useful if you have different language content on your site. If Polylang is installed, the current Polylang post language will be used. Return value should be in Syllable library format, for example en-us.

add_filter('syllable_hyphenator_current_locale', function () {
  return 'en-us';
});

syllable-hyphenator's People

Contributors

joppuyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

syllable-hyphenator's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.