2017 © Pedro PelĂĄez
 

library theme-lib-links

Collection of link helper functions for WordPress themes

image

mindkomm/theme-lib-links

Collection of link helper functions for WordPress themes

  • Tuesday, February 13, 2018
  • by gchtr
  • Repository
  • 3 Watchers
  • 1 Stars
  • 136 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 31 % Grown

The README.md

Links

Collection of link helper functions for WordPress themes., (*1)

Installation

You can install the package via Composer:, (*2)

composer require mindkomm/theme-lib-links

Functions

Name Summary Type Returns/Description
get_link_attributes Gets href attribute for a link tag with proper target and rel attributes. string or bool An href attribute with target and rel attributes, when necessary. Returns false if input is empty.
is_external_url Checks if a URL is external or internal. bool Whether the URL is external.
make_anchor_link Converts an URL to an anchor link. string The updated URL.
url_to_domain Converts an URL to just the domain name together with the TLD. string The domain part of the URL.

Converts an URL to an anchor link., (*3)

Prefix the last segment of a URL with a # to use it as an anchor link., (*4)

make_anchor_link( string $url ), (*5)

Returns: string The updated URL., (*6)

Name Type Description
$url string URL to turn into an anchor link.

PHP, (*7)

// Output: https://www.mind.ch/onepager#subsection
echo make_anchor_link( 'https://www.mind.ch/onepager/subsection' );

is_external_url

Checks if a URL is external or internal., (*8)

is_external_url( string $url ), (*9)

Returns: bool Whether the URL is external., (*10)

Name Type Description
$url string URL to be parsed.

PHP, (*11)

if ( is_external_url( 'https://example.org' ) ) {
    // Do something
}

Twig, (*12)

{% if is_external_url('https://www.example.org') %}
    {# Do something #}
{% endif %}

url_to_domain

Converts an URL to just the domain name together with the TLD., (*13)

url_to_domain( string $url, bool $strip_www = false, int|bool $limit = false ), (*14)

Returns: string The domain part of the URL., (*15)

Name Type Description
$url string The URL to convert.
$strip_www bool Optional. Whether to strip the "www" part of the domain. Default false.
$limit int|bool Optional. Limit to a certain amount of characters. Default false.

PHP, (*16)

<?php $domain = 'https://www.mind.ch/post/blablabla?param=wow'; ?>
<a href="<?php echo $url; ?>"><?php echo url_to_domain( $domain ); ?></a>

Twig, (*17)

{# url = 'https://www.mind.ch/post/blablabla?param=wow' #}
<a href="{{ url }}">{{ url_to_domain(url) }}</a>

Gets href attribute for a link tag with proper target and rel attributes., (*18)

Checks if the URL is internal or external. Adds a target="_blank" for external urls. Inspired by http://stackoverflow.com/a/25090564/1059980. To catch a security vulnerability, the attribute rel="noopener noreferrer" is added, see https://mathiasbynens.github.io/rel-noopener/ for more info., (*19)

get_link_attributes( string $url ), (*20)

Returns: string|bool An href attribute with target and rel attributes, when necessary. Returns false if input is empty., (*21)

Name Type Description
$url string URL to be parsed.

PHP, (*22)

<a <?php echo get_link_attributes( 'https://www.mind.ch/blog' ); ?>>MIND Blog</a>

Twig, (*23)

<a {{ get_link_attributes(url) }}>MIND Blog</a>

Twig functions

You need Timber to use these functions., (*24)

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., (*25)

The Versions

13/02 2018

dev-master

9999999-dev

Collection of link helper functions for WordPress themes

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

13/02 2018

1.0.0

1.0.0.0

Collection of link helper functions for WordPress themes

  Sources   Download

MIT

The Requires

  • php >=7.0.0