PagesNames::uniquePageName() method

Get a unique page name

  1. If given no arguments, it returns a random globally unique page name.
  2. If given just a $name, it returns that name (if globally unique), or an incremented version of it that is globally unique.
  3. If given both $page and $name, it returns given name if unique in parent, or incremented version that is.
  4. If given just a $page, the name is pulled from $page and behavior is the same as #3 above.

The returned value is not yet assigned to the given $page, so if it is something different than what is already on $page, you’ll want to assign it manually after this.

Usage

// basic usage
$string = $pagesNames->uniquePageName();

// usage with all arguments
$string = $pagesNames->uniquePageName($name = '', $page = null, array $options = []);

Arguments

NameType(s)Description
name (optional)string, Page, array

Name to make unique You may optionally substitute the $page argument or $options arguments here, if that is all you need.

page (optional)
options (optional)array
  • parent (Page|null): Optionally specify a different parent if $page does not currently have the parent you want to use.
  • language (Language|int): Get unique for this language (if multi-language page names active).
  • page (Page|null): If you specified no $page argument, you can optionally bundle it in the $options array.
  • name (string): If you specified no $name argument, you can optionally bundle it in the $options array.

Return value

string

Returns unique name


PagesNames methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK