Add meta to custom post type archive-page

#127360
  • Resolved Steffan S.
    Rank Math free

    Dear RankMath Team,
    Thanks for this wonderful plugin!
    I have the following problem:

    – I set up archive-car.php (‘car’ stands for a custom post_type) as preview page of all available categories. Since the content of the archive page cannot be edited in WordPress, I created a page with the title ‘Car’ instead and manually pasted its content into archive-car.php:

    $page_car = get_page_by_title( "Car" );
    if ( ! empty( $page_car ) ) {
        echo $page_car->post_content;
    }

    – taxonomy-car_category.php shows the sub-categories of car (which is working perfectly because there are categories in wordpress available here which can be edited for RankMath)
    – How can I insert the RankMath meta information (like description, keywords etc.) of the ‘Car’ page into the Archive page?
    Currently there are only nonsense meta information available (I don’t know where it come from):

    <meta name="description" content="Car Archive &ndash; [HomepageName]"/>
    <meta property="og:locale" content="en_EN">
    <meta property="og:type" content="car">
    <meta property="og:title" content="Car &ndash; [HomepageName]">
    <meta property="og:description" content="Car Archive &ndash; [HomepageName]">
    <meta property="og:url" content="https://www.[HomepageName].com/car/">
    <meta property="og:site_name" content="[HomepageName]">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="Car &ndash; [HomepageName]">
    <meta name="twitter:description" content="Car Archive &ndash; [HomepageName]">
    <... class="rank-math-schema">{
        "@context": "https://schema.org",
        "@graph": [
            {
                "@type": "Person",
                "@id": "https://www.[HomepageName].com/#person",
                "name": "[HomepageName]",
                "url": "https://www.[HomepageName].com",
                "email": "support@[HomepageName].com",
                "image": {
                    "@type": "ImageObject",
                    "url": "https://www.[HomepageName].com/wp-content/uploads/2020/12/cropped-[HomepageName]2**@3*****"
                }
            },
            {
                "@type": "WebSite",
                "@id": "https://www.[HomepageName].com/#website",
                "url": "https://www.[HomepageName].com",
                "name": "[HomepageName]",
                "publisher": {
                    "@id": "https://www.[HomepageName].com/#person"
                },
                "inLanguage": "en-EN"
            },
            {
                "@type": "CollectionPage",
                "@id": "https://www.[HomepageName].com/car/#webpage",
                "url": "https://www.[HomepageName].com/car/",
                "name": "Car &ndash; [HomepageName]",
                "isPartOf": {
                    "@id": "https://www.[HomepageName].com/#website"
                },
                "inLanguage": "en-EN"
            }
        ]
    }</...>

    – Is it also possible to add manually an item list like this to archive-car.php?

            {
                "@type": "ItemList",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "url": "https://www.[HomepageName].com/car/bwm-as-an-offroad-car/"
                    },
                ],
                "mainEntityOfPage": {
                    "@id": "https://www.[HomepageName].com/car_category/offroad/#webpage"
                }
            }

    I hope you can help me further.

    Many thanks in advance.

    Greetings
    Steffan

    (By the way, I use the following permalink structure: /%category%/%postname%/ )

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    You can use the filters in the link below to add metadata (title, description, keywords) to your archive-car page:
    https://rankmath.com/kb/filters-hooks-api-developer/#metadata

    I hope that helps. Thank you, and looking forward to your update.

    Hello,

    Many thanks for your quick answer. Is there a way to add all metadata of the ‘car’ page to the archive-car page at once? As far as I can see, there are only filters for each meta-information separately. Is there an easy way to add all meta information from one page to another? Otherwise that would be a lot of code.

    Greetings

    Hello,

    How many pages are there that you wish to change?

    If it’s a single page, you can easily edit this by heading to WordPress dashboard > Your custom post type > Archive page

    You should also consider adding the related meta in Rank math > Titles & Meta > Your archive post type.

    If your pages are not editable via WordPress or aren’t seen under Rank math > Titles & Meta then it means your pages are not following the required WordPress structure for archive pages.

    If all this still doesn’t help, please record a screencast to explain the issue using a tool like https://www.loom.com and share it in the sensitive section so we can clearly understand this and assist you accordingly.

    Looking forward to helping you. Thank you.

    Wow, you really have an excellent support!
    The page archive-car.php is working perfectly by changing content in the category and Rank math > Titles & Meta > post_type – thanks.

    Unfortunately the taxonomy-car_category.php file (https://developer.wordpress.org/themes/basics/template-hierarchy/#custom-taxonomies) is not working and is not editable in WordPress as I know. Is there a way to use all meta information from one page to use it on another page?
    As said, I can do something like this but it is very inefficient:

    
    add_filter( 'rank_math/frontend/title', function( $title ) {
        if(is_post_type_archive('car')) {
    	    return ...; //get title meta information from get_page_by_title("Car")
        }
        return $title;
    });
    add_filter( 'rank_math/frontend/description', function( $description ) {
        if(is_post_type_archive('car')) {
    	    return ...; //get description meta information from get_page_by_title("Car")
        }
    	return $description;
    });
    add_filter( 'rank_math/frontend/keywords', function( $keywords ) {
        if(is_post_type_archive('car')) {
    	    return ...; //get keyword meta information from get_page_by_title("Car")
        }
    	return $keywords;
    });
    
    //etc. ...
    

    Is there a way to get ALL meta information of a page to add it to another at once?

    For further understanding – I have the following structure:

    [main_path]/car/  #shows all car_category categories from the custom taxonomy and previews 4 <custom_post=car> articles
    [main_path]/car/<custom_post article> #shows the <custom_post=car> article
    [main_path]/car_category/<category> #shows all article previews to the related <category> (not only 4 preview articles like [main_path]/car/ does)

    Hello,

    Sorry for the delay.

    Unfortunately, we don’t have that option to get all the meta-information of a page and add it to another page at once. You may need to set it up or copy all the meta-information manually to the other page.

    Thank you, and please don’t hesitate to contact us if you need further assistance.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Add meta to custom post type archive-page’ is closed to new replies.