• Resolved Dmitry

    (@stranger03)


    Hello Anh Tran! I noticed an issue on the author pagination pages. If I want to change part of the title related to the page number on all pagination pages, for example, “Page 2” to something like “Page 2 of 10”, nothing changes on the author pagination pages.

    I am using the following code to change part of the title:

    add_filter('document_title_parts', function($title_parts) {
        if (is_paged()) {
            global $wp_query;
            $total_pages = $wp_query->max_num_pages;
            // Get the current page number
            $paged = get_query_var('paged');
            // Set the desired text instead of "Page 2".
            $title_parts['page'] = 'Page ' . $paged . ' of ' . $total_pages;
        }
        return $title_parts;
    });

    For example, I can easily change the title separator on all pages with one line of code:
    add_filter('document_title_separator', fn() => '|');

    However, I cannot change the part of the title related to the page number on the author pagination pages using the ‘document_title_parts‘ filter. I do not encounter this issue when the plugin is deactivated.

    By the way, why isn’t the dynamic variable {{ page }} used in the Meta title of the homepage?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi @stranger03 ,

    Slim SEO will disregard the title parts and let people overrides the values in the settings page. So what you filter doesn’t matter. It’s better to filter the value of {{ page }} instead, like this:

    add_filter( 'slim_seo_data', function( $data ) {
    if ( is_paged() ) {
    global $wp_query;
    $total_pages = $wp_query->max_num_pages;
    // Get the current page number
    $paged = get_query_var('paged');
    // Set the desired text instead of "Page 2".
    $data['page'] = 'Page ' . $paged . ' of ' . $total_pages;
    }
    return $data;
    } );

    This will change the value of {{ page }}. It will work for all paginated pages.

    Thread Starter Dmitry

    (@stranger03)

    I noticed that “document_title_parts” changes parts of the title on all paginated pages except for author pages.
    Meanwhile, “slim_seo_data” does the opposite: it changes the title part on author pagination pages but not on the others.
    Additionally, on author pagination pages, there is no separator between the author’s name and “Page 2.”
    For example, on the page https://example.com/author/admin/page/2/, the title appears as:
    Admin Page 2 of 5 – My Blog
    But it should be:
    Admin – Page 2 of 5 – My Blog

    Plugin Author Anh Tran

    (@rilwis)

    Hi @stranger03,

    I noticed that “document_title_parts” changes parts of the title on all paginated pages except for author pages.
    Meanwhile, “slim_seo_data” does the opposite: it changes the title part on author pagination pages but not on the others.

    Sorry, I posted incorrect info. Slim SEO works this way:

    When you don’t change any default title format (in Settings > Meta Tags tab), Slim SEO will use the default WordPress format, which will use the document_title_parts. If you modify the value in the Settings > Meta Tags tab, then Slim SEO will use your entered format, which will ignore the document_title_parts filter, and use the slim_seo_data filter.

    To make the code works in both case, please update the snippet to this:

    add_filter( 'slim_seo_data', 'change_pagination_text' );
    add_filter( 'document_title_parts', 'change_pagination_text' );

    function change_pagination_text( $data ) {
    if ( ! is_paged() ) {
    return $data;
    }

    global $wp_query;
    $paged = get_query_var( 'paged' );
    $data['page'] = 'Page ' . $paged . ' of ' . $wp_query->max_num_pages;

    return $data;
    }

    Additionally, on author pagination pages, there is no separator between the author’s name and “Page 2.”

    Thanks for reporting this. We’ve just fixed this bug, and it will be available in the next version.

    Plugin Author Anh Tran

    (@rilwis)

    Ignore: duplicated post.

    • This reply was modified 5 days, 17 hours ago by Anh Tran.
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.