Skip to content

New WP_SEO_Format_Page_Number tag formatter #160

@renatonascalves

Description

@renatonascalves

Description

Introduce a new #page_number# formatter:

/**
 * Add #page_number# to WP SEO Formatting Options
 */
class WP_SEO_Format_Page_Number extends WP_SEO_Formatting_Tag {

	/**
	 * The name of the tag.
	 *
	 * @var string
	 */
	public $tag = '#page_number#';

	/**
	 * The description of the tag.
	 *
	 * @return string
	 */
	public function get_description(): string {
		return __( 'Replaced with page number for archive pages.', 'wp-seo' );
	}

	/**
	 * The replacement value for the tag.
	 *
	 * @return string
	 */
	public function get_value(): string {
		if ( is_archive() ) {
			global $wp_query;

			$page = 1;

			if ( $wp_query->is_paged() ) {
				$page = $wp_query->query_vars['paged'];
			}

			if ( $page > 1 ) {
				/* translators: Page Number */
				return sprintf( esc_html__( 'Page %s |', 'wp-seo' ), absint( $page ) );
			}
		}

		return '';
	}
}

Use Case

A new #page_number# formatter to be used in archive pages.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions