Apply RankMath Data of a post to another with filters

#121780
  • Resolved Upwwward
    Rank Math free

    Hi dear support ;

    I am trying to apply all RankMath settings of a CTP term to a special archive page (where I modified the main query with with pre_get_posts based on the url structure).

    I have succeed to apply the title and desciption like this :

    
    /* With Rankmath SEO : change SEO Title */
    function inject_seo_title($title)
    {
    	if( ! is_admin() && is_archive() && get_product_type_from_url() != null ) {
    		$title = RankMath\Post::get_meta( 'title', get_seo_content_id() );
    	}
     
        return $title;
    }
    add_filter( 'rank_math/frontend/title', 'inject_seo_title');
    
    /* With Rankmath : Change SEO Description */
    function inject_seo_description( $description ){
    	global $post;
    	
    	if( ! is_admin() && is_archive() && get_product_type_from_url() != null ) {
    		$description = RankMath\Post::get_meta( 'description', get_seo_content_id() );
    	}
     
        return $description;
    }
    add_filter( 'rank_math/frontend/description', 'inject_seo_description');
    

    But I cannot succeed to change the thumbnails.
    For now I have this for the Facebook one :

    
    /* With Rankmath : Change SEO Thumbnail */
    function inject_seo_thumbnail( $attachment_url ){
    	
    	if( ! is_admin() && is_archive() && get_product_type_from_url() != null ) {
    		$attachment_url = "https://mysite.com/wp-content/uploads/2020/05/default-thumbnail.png"; // a simple example
    	}
     
        return $attachment_url;
    }
    add_filter( "rank_math/opengraph/facebook/image", 'inject_seo_thumbnail');
    

    What am I doing wrong ?
    Is there a better way to transfer all RankMath data of a post to another with filters ?

    Thank you 🙏

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay and for any inconvenience this issue may have caused you.

    Unfortunately, we don’t have that feature. To attain that functionality, you may need to hire a developer or coder to work properly. You can also check our guides using filters in the link below:
    https://rankmath.com/kb/filters-hooks-api-developer/

    I hope that helps. 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 1 replies (of 1 total)

The ticket ‘Apply RankMath Data of a post to another with filters’ is closed to new replies.