Support » Plugin: Yoast SEO » Pagination with %%page%% in description also for og

  • Resolved Noob2000

    (@noob2000)


    I tried to add %%page%% to my pages titles AND descriptions as I had issues in Google Search Console with duplicated meta descriptions and titles with pagination pages.

    When checking source code for titles it’s working fine and the output is “(…)| Page x of y” but in description it’s still showing %%page%%.

    Strang thing is in og:description source code shows “(…)| Page x of y” like it should.

    But why not in <meta name="description" content="(..) | Page x of y" />?

    Thank you.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    We are sorry to hear that you’re having trouble using the %%page%% template variable on the paginated archives meta description. We are afraid to say that we were unable to reproduce the issue on our end while using the latest version of WordPress alongside the default 2021 theme. We can confirm the %%page%% template variable works fine as expected when using it on the meta description field on paginated archives pages (i.e. the default front page that shows all the available blog posts).

    In this case, can you please confirm where exactly are you using the %%page%% template variable? Are you using it on a custom post type or somewhere else? Does the issue occur when using the default 2021 theme?

    We look forward to hearing from you.

    Thread Starter Noob2000

    (@noob2000)

    Thank you.

    I am using Avada theme. I put %%page%% in a costum page title AND description. I am running an online shop and have a product catalogue on my starting page. That’s why I need pagination there.

    Didn’t check with 2021. Will try that.

    Meanwhile I found an interesting workaround by using the following plugin code and added a filter for the open graph description (og:description). That combined with your variable %%page%% in title did the trick. (Just if anyone else having the same issue and does a search on this I’ll post it below.)

    I now have what I want:

    – meta description with “(…)| Page: x”
    – title with “(…)| Page x from y”
    – og:description with “(…)| Page: x”
    – og:title with “(…)| Page x from y”

    The plugin code (simply generate folder with plugin name and copy the following code as php file into that newly created folder):

    <?php # -*- coding: utf-8 -*-
    /**
     * Plugin Name: T5 Add page number to title
     * Description: Adds <code> | Page $number</code> to the page title.
     * License:     MIT
     * License URI: http://www.opensource.org/licenses/mit-license.php
     */
    
    if ( ! function_exists( 't5_add_page_number' ) )
    {
        function t5_add_page_number( $s )
        {
            global $page;
            $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
            ! empty ( $page ) && 1 < $page && $paged = $page;
    
            $paged > 1 && $s .= ' | ' . sprintf( __( 'Seite: %s' ), $paged );
    
            return $s;
        }
    
        add_filter( 'wp_title', 't5_add_page_number', 100, 1 );
        add_filter( 'wpseo_metadesc', 't5_add_page_number', 100, 1 );
        add_filter( 'wpseo_opengraph_desc', 't5_add_page_number', 100, 1);
    }

    add_filter( 'wp_title', 't5_add_page_number', 100, 1 ); adresses the og:title
    add_filter( 'wpseo_metadesc', 't5_add_page_number', 100, 1 ); adresses the meta description
    add_filter( 'wpseo_opengraph_desc', 't5_add_page_number', 100, 1); adresses the og:descripton

    Plugin Support Jerlyn

    (@jerparx)

    Hi @noob2000

    Thank you for sharing your workaround! This will surely help other users!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination with %%page%% in description also for og’ is closed to new replies.