Custom Pretty Permalinks

WordPress Plugin Staff List – Custom Pretty Permalinks

You can extend built-in permalinks and add your own set of options to:
Extending pretty permalinks require custom coding.
Our support is limited to detailed instructions you’ll find below. It doesn’t include custom extensions.

How to add custom pretty permalinks

You have two options when it comes to adding custom permalinks:
  1. Add the code to your theme.
  2. Create a custom plugin.
First method is not recommended, since custom code can be overwritten by theme updates. A better option is to create a simple WordPress plugin.

Plugin Example

An example of custom permalinks plugin that you can customize and use in your own installation.
<?php
/**
* Plugin Name: Staff List Custom Permalinks
* Description: Adds custom rewrite rules for Staff List single page.
* Author: abcFolio.
* Version: 0.0.1
*/
add_filter('rewrite_rules_array', 'abcfslcp_rewrite_rules');

function abcfslcp_rewrite_rules( $rules ) {
    $newRules = array(
        'professore/profilo/([^/]+)/?$' => 'index.php?pagename=professore/profilo&staff-name=$matches[1]',
        'attorney/([^/]+)/?$' => 'index.php?pagename=attorney&staff-name=$matches[1]'
    );
    return $newRules + $rules;
}

function abcfslcp_is_single_pretty( $sPageUrl ){
    if( substr($sPageUrl, -8) == 'attorney' ) { return true; }
    return false;
}

function abcfslcp_custom_page_names(){
    $ppCustomPages = array( 'attorney' );
    return $ppCustomPages;
}

Plugin Parts

filter rewrite_rules_array

add_filter('rewrite_rules_array', 'abcfslcp_rewrite_rules');
Filter section is used to refresh WordPress rewrite rules (to add your own rules).

function abcfslcp_rewrite_rules ($rules)

function abcfcpp_rewrite_rules( $rules ) {
    $newRules = array(
        'professore/profilo/([^/]+)/?$' => 'index.php?pagename=professore/profilo&staff-name=$matches[1]',
        'attorney/([^/]+)/?$' => 'index.php?pagename=attorney&staff-name=$matches[1]'
    );
    return $newRules + $rules;
}
Contains two rewrite rules:
  1. faculty/profile – page profile can be a subpage of faculty.
  2. attorney – pretty permalink page can be named: attorney.
Subpage rule
professore/profilo/([^/]+)/?$' => 'index.php?pagename=professore/profilo&staff-name=$matches[1]
Your profile page can be a subpage of faculty page.
URL example: http://mydomain.com/professore/profilo/john-smith
Page name rule
attorney/([^/]+)/?$' => 'index.php?pagename=attorney&staff-name=$matches[1]
Adds custom page name. You can use attorney as a page name for pretty permalinks.
URL example: http://mydomain.com/attorney/john-smith
Rewrite section is not limited to a single rule. You can add as many subpage and page rules as required.

function abcfcpp_is_single_pretty ($sPageUrl)

function abcfslcp_is_single_pretty( $sPageUrl ){
    if( substr($sPageUrl, -8) == 'attorney' ) { return true; }
    return false;
}
This function is required only if you add custom page name e.g., attorney to rewrite rules.
Function name has to be: abcfslcp_is_single_pretty. It can’t be changed.
For each page name rule in rewrite rules there has to be matching entry in abcfslcp_is_single_pretty.
if( substr($sPageUrl, -8) == 'attorney' ) { return true; }

Refresh Rewrite Rules

To activate your own pretty permalinks settings you need to refresh WordPress rewrite rules.

  1. WordPress admin Settings > Permalinks.
  2. On the Permalink Settings page click Save Settings.

Don’t make any changes. Just open the page and click Save.

  • You need to do it only once, after you install and activate your plugin.
  • You have to run the refresh procedure again after changes to rewrite rules.

Rewrite Rules Inspector

Rewrite Rules Inspector is a simple development tool for viewing all of the rewrite rules registered with your site.