WP Manifestindependent plugin directory
manifest / utilities / jw-our-shortcodes

Our Shortcodes

WordPress plugin defining extra shortcodes: [if] (including Block Editor functionality), [copyright], [years], and [nowrap].

by Jonathan Whiteland · github.com/jonathanwhitelandnet/jw-our-shortcodes

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/jonathanwhitelandnet/jw-our-shortcodes/archive/refs/heads/main.zip

Readme

Our Shortcodes

A powerful, lightweight WordPress plugin that provides a suite of utility shortcodes ([if], [copyright], [years], and [nowrap]) alongside a flexible Block Visibility addition for the Gutenberg block editor.

This plugin allows you to dynamically show/hide content, automate year-based date calculations, prevent awkward text wrapping, and restrict Gutenberg blocks based on roles, URLs, IP addresses, URL parameters, or custom PHP functions.


Key Features

  • Dynamic Content Control – [if]: Conditionally render content based on user status, user roles, current URLs, IP addresses, or custom functions while using logical expressions (and, or, not).
  • Gutenberg Block Visibility: Bring the full power of the conditional engine into the block editor. Control visibility settings for any core or custom block directly from the inspector sidebar.
  • Automated Copyrights – [copyright]: Outputs an always accurate copyright statement with automated year range tracking and lining numeral styling support.
  • Smart Age/Duration Calculator – [years]: Displays years elapsed since a specific year or date, automatically rounding to the nearest half-year for durations under 5 years.
  • Layout Polish – [nowrap]: Keeps critical words or punctuation together, forcing clean inline text flows without line breaks.

Detailed component documentation

1. Conditional display of content – [if] shortcode

The [if] shortcode conditionally renders text. It also features a built-in shorthand if-else separator using the pipe (|) character.

[if condition] show this if true | show this if false [/if]

Supported conditions:

  • Authentication: [if logged_in] or [if not_logged_in]
  • User Roles: Checks if the user has specific roles. Supports comma-separated lists.
    • [if role="guest, seller"] ... [/if]
    • [if not_role="customer"] ... [/if]
  • URL / Page Paths: Targets specific page slugs (requires pretty permalinks enabled).
    • [if url="privacy-policy, cookie-policy"] ... [/if]
    • [if not_url="/"] ... [/if] (Hides content on the homepage)
  • IP Addresses & Named IP Lists: Match client IP addresses.
    • [if ip="51.6.184.227, 127.0.0.1"] ... [/if]
    • Named IP Lists: For advanced administration, you can supply a lowercased slug (e.g., [if ip="birmingham"]). The plugin will look inside your securely configured path for a text file named birmingham.txt containing a list of authorized IPs (one per line).
  • URL GET Query Parameters:
    • Check for presence/absence: [if query="reason"] or [if reason] / [if not_reason]
    • Check for key-value matches: [if reason="exists"] ... [/if] or [if not_reason="failed"] ... [/if]
  • PHP Functions & Globals: Evaluates existing global functions or global variables dynamically (coerced safely to booleans).
    • [if is_privacy_policy] ... [/if]
    • [if global="is_apache"] ... [/if]

Note: Bare names of functions, globals, and GET parameters are checked/matched in that order. Use function=, global=, or query= to override that precendence.

Logical combinations:

You can chain multiple conditions together. By default, conditions are combined using AND. You can explicitly add and or or operators.

  • [if logged_in url="account"] ... [/if] (Logged in AND on the account page)
  • [if logged_in or url="/"] ... [/if] (Logged in OR on the homepage)

Note: Mixing and and or within a single shortcode is not supported and will render a syntax error cross symbol (✖).


2. Gutenberg "Block Visibility" integration

Brings the expression logic of the [if] engine directly into the Gutenberg Block Editor.

  • When enabled, a new Block Visibility section appears in the Inspector Controls sidebar for selected block types.
  • Simply type any valid [if] conditional syntax directly into the [IF] CONDITION text field (e.g., logged_in, role="guest", or wp_is_mobile).
  • Convenience feature: If block visibility is configured for "specific blocks", you can toggle and permit new block types seamlessly straight from the block editor sidebar without reloading. Changes synchronize globally across all active blocks on the screen.

Note: Consider using Nick Diego's Block Visibility Plugin instead which offers many additional conditions in a more user-friendly way.


3. Copyright message formatting – [copyright] shortcode

Simplifies footer maintenance by outputting a clean copyright string with automatic year configurations.

Examples & attributes:

  • [copyright]© 2026
  • [copyright]Whiteland Services[/copyright]© Whiteland Services 2026
  • [copyright since="2020"]Jonathan Whiteland,[/copyright]© Jonathan Whiteland, 2020-2026
  • Attributes:
    • since: The start year. If it matches the current year or is omitted, only the current year displays. Otherwise, a dash-separated range is generated.
    • lining: Automatically forces font-variant-numeric: lining-nums; ensuring clean modern numeral heights even on older or stylized font families (default: Y).

4. Dynamic display of "years since" – [years] shortcode

Calculates the absolute difference in years between a starting date/year and the present moment.

Examples & attributes:

  • [years since=1889]137
  • [years since=1976 lining=no]50 (Disables lining numerals style)
  • Smart Fraction Tracking: For modern dates (less than 5 years ago), the plugin accepts full date strings (YYYY-MM-DD or DD/MM/YYYY) and calculates to the nearest half-year, rendering formatted fractions:
    • [years since=2024-06-01] (assuming current date is mid-2026)
  • Fallback: If the since attribute is missing or invalid, it gracefully renders the word several.

5. Line-Wrap controller – [nowrap] shortcode

WordPress often handles line-breaks awkwardly, splitting text or punctuation marks at edge margins. The [nowrap] shortcode binds its inner contents safely using inline styles.

Example:

  • preventing [nowrap]"…corrosion[/nowrap] from insect infestation
  • Output HTML: preventing <span style='text-wrap: nowrap;'>"…corrosion</span> from insect infestation

Installation

  1. Download or clone this repository into a folder named our-shortcodes.
  2. Upload the our-shortcodes directory to your WordPress site's /wp-content/plugins/ directory.
  3. Navigate to the Plugins panel in your WordPress Dashboard and click Activate.

Configuration & settings

Navigate to Settings → Block Visibility in your WordPress admin menu to configure global preferences:

  1. Visibility Panel:
    • Disabled: Turns off Gutenberg block visibility integrations completely.
    • Enabled for all block types: Applies the inspector controls field globally across all blocks.
    • Enabled for these blocks: Limits visibility inspector tools to a specific comma-separated whitelist (e.g., core/paragraph, core/list, core/columns).
  2. Named IP Path:
    • Provide the absolute server file path directory where your named IP .txt files reside (e.g., /var/www/sites/ip/).
    • "WordPress Studio" workaround: The plugin automatcially detects local development under WordPress Studio and disables this feature.

License

This project is licensed under the GNU General Public License v2.0 or later – see the LICENSE.txt file for full warranty disclaimers and modification permissions.

Note: The IP Geolocation API – used for a non-essential hint on the Block Visibility Settings page – is for non-commercial use only. If this plugin is used in a commercial context, this functionality can be safely disabed by changing the JW_OS_GEOLOCATE constant to FALSE.

Read the full README on GitHub →