Displaying of custom post type in SEO title

#70838
  • Resolved Johan
    Rank Math free

    Hi there guys,

    I’m having a little trouble getting my required SEO Title needs.

    The result that I am look for is as follows:

    Title – Custom Term from current post type – Entry from an additional post type – Sitename

    The only problem comes in trying to display information from the additional post type.

    More information in Sensitive Data

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

    Thank you for contacting Rank Math today.

    You can use this filter: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-variables to add the variables that reference the Agency CPT then use the variable in your title settings. If you are not a programmer, you will have to seek some help from one to correctly customize this.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Johan
    Rank Math free

    Hey there Michael,

    Thanks for the feedback.

    I have attempted the information provided as follows:

    add_action( 'rank_math/vars/register_extra_replacements', 
     function(){
     rank_math_register_var_replacement(
     'agency',
     [
     'name'        => esc_html__( 'agency', 'rank-math' ),
     'description' => esc_html__( 'display agency of listing', 'rank-math' ),
     'variable'    => 'agency',
     'example'     => 'agency_callback()',
     ],
     'agency_callback()'
     );
    });

    But this results in the following warning:

    Warning: call_user_func() expects parameter 1 to be a valid callback, function ‘agency_callback()’ not found or invalid function name in /home/propejmo/public_html/wp-content/plugins/seo-by-rank-math/includes/replace-variables/class-variable.php on line 177

    Any guidance would be appreciated?

    Hello,

    You will have to create a call back function to get the details from your CPT for example:

    
    add_action( 'rank_math/vars/register_extra_replacements', 
     function(){
     rank_math_register_var_replacement(
     'agency',
     [
     'name'        => esc_html__( 'agency', 'rank-math' ),
     'description' => esc_html__( 'display agency of listing', 'rank-math' ),
     'variable'    => 'agency',
     'example'     => 'agency_callback()',
     ],
     'agency_callback'
     );
    });
    
    //your callback function
    function agency_callback(){
      return 'agency';
    }
    

    Hope that helps. If you have any further question(s), please let us know. Thank you.

    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘Displaying of custom post type in SEO title’ is closed to new replies.