MOD: Include subpages in SimpleSEO

Post Reply
grimblefritz
Posts: 16
Joined: Tue Apr 25, 2023 1:21 pm

MOD: Include subpages in SimpleSEO

Post by grimblefritz »

The way I'm using WCMS, I have a hidden top-level menu item that does nothing but hold subpages I don't want in the menu. I would, however, like to have the subpages (that are not themselves hidden) in the sitemap.

SimpleSEO doesn't descend into the subpages. It only looks at the top level. So, this mod is good for that, too.

The following mod drills into the subpages, and it is recursive. You can have as many levels of subpages as you need.

This is for the version 3.2.1 of simple-seo.php

Find the following comment and foreach:

Code: Select all

    // CMS pages
    foreach ($Wcms->get('config', 'menuItems') as $item) {
and replace the entire foreach with this:

Code: Select all

    foreach ($Wcms->get('config', 'menuItems') as $item) {
        simpleSeoPage($item, $output, $BASE_URL);
    }
At the top of the script, after the global $Wcms, add this function:

Code: Select all

function simpleSeoPage($item, &$output, $BASE_URL) {
    if ($item->visibility !== 'hide') {
        $output[] = $BASE_URL . $item->slug;
    }
    foreach ($item->subpages as $subpage) {
        simpleSeoPage($subpage, $output, $BASE_URL . $item->slug . '/');
    }
}
The sitemap.txt will now include any subpages that are not hidden.

Ideally, if someone would like to tackle it (I'm not interested), on the admin page there should be a checkbox for "Include subpages?"
Post Reply