Rankmath video url (DL) automatic in Content URL ?

#244594
  • Resolved Little Carpenter
    Rank Math free

    i use Rankmath in my WP site I upload my videos to the download host and put them in the posts (As follows)

    Every time I have to create a schema for the videos I have again put the video link manually in Rankmath

    I want the video to be inserted like the SEO title that is automatically inserted in the schema The SEO title is automatically like this=> %seo_title%

    In my database, the video URL is stored in “_studiare_course_video” in the “ktfjv_postmeta” table

    I used this code but it did not work=> %_studiare_course_video%

    please Help me Thanks.

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

    Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.

    Rank Math has its own set of variables and the variable you are trying to use is not registered on Rank Math.

    You would need to create a custom variable using our filter and assign the value from the meta you are trying to add.

    /**
    * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
    * Snippet to register variable that will return all terms in custom taxonomy
    */
    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'my_custom_variable', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'my_custom_variable', /* the actual variable: %my_custom_variable% */
    	   'example'     => var_name_call_back(),
    	   ],
    	   'var_name_call_back'
       );
    });
    function var_name_call_back(){
    return "Example value"; // return value here.
    }

    After you modified the code above as per your preferences, you would need to use the variable %my_custom_variable% and this should work on the schema fields.

    Let us know how it goes. We are looking forward to helping you.

    Thanks for answers

    I read all your tips
    But I’m not a programmer and I do not understand

    All I want to do is use a record in my database to field the video URL (content url) in the Rankmath

    I still do not understand how the above information (your cods) wants to use my database record, because there is no name of the database and tables and records.

    See my database image again

    I’m really sorry that the questions are amateur, because nowhere else helped me in this .

    Hello,

    I am sorry if my previous answer isn’t helping you with your issue. The code I shared is just a placeholder to show you the basics of modifying or creating a Rank Math variable that can be used for your schema field.

    Here’s a custom filter I made for you, please check:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'studiare_video_url', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'studiare_video_url', /* the actual variable: %studiare_video_url% */
    	   'example'     => var_name_call_back(),
    	   ],
    	   'var_name_call_back'
       );
    });
    function var_name_call_back(){
    	global $post;
        return get_post_meta( $post->ID, '_studiare_course_video' );
    }

    In order to make this work, please insert this code into your theme’s functions.php file. You may refer to our guide here: https://rankmath.com/kb/wordpress-hooks-actions-filters/#functions-php-file

    Then use the custom variable %studiare_video_url% in your video schema’s Content URL field as shown below: https://i.rankmath.com/L3aHyU

    Hope that helps. Let us know how it goes.

    You are very kind to me
    Thank you so much for your consistent guidance

    I did all the steps correctly
    In the first step, I put the code in my template function

    In the second step, I used a custom variable in my video schema’s Content URL field

    I did all the steps correctly but does not work
    The source is as follows (view-source)

    I use WooCommerce and this code is in my products.

    Thanks again for your time
    I hope this problem is solved for me .

    Hello,

    In this case, we might need to take a closer look at your admin dashboard as well as your FTP. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Thanks for following up
    I sent you the hosting and WordPress information

    The site, which I sent to you, is still in the experimental stage (Edited)Restore original

    Note that Schema should be used in products

    After solving this problem, I will use the professional version for myself and my friends and we will buy your product.

    Again, I thank you for mohebi that me and my friends.

    Hi
    I hope you fine

    Can’t find a solution to my problem yet?
    thanx.

    Hello,

    We apologize for the unexpected delay.

    I have changed the code a bit as it was returning an array that won’t be displayed by the variable.

    The variable is now displaying the video URL as you can see in this screenshot: https://i.rankmath.com/NzlrC7

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thanks for following up and fixing the problem
    The problem is completely solved
    May I ask which file did you modify?

    you just change the Function.php file?

    Because I have to change this on my other sites as well

    Thanks again for your great support

    Hello,

    I am glad that resolves the issue.

    Sure, what I did is I change this line:

    return get_post_meta( $post->ID, '_studiare_course_video' );

    to this:

    return get_post_meta( $post->ID, '_studiare_course_video', true);

    This will make the function return a single value making it work on variables.

    https://developer.wordpress.org/reference/functions/get_post_meta/

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

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

You must be logged in to reply to this ticket.