Christian ( Era )

#520236
Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

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

    There’s no way to change the output of the existing variables using a code snippet as those are hard-coded into the plugin. However, if you still want to do so, you can continue editing the plugin files.

    To do that, please head over to wp-content/plugins/seo-by-rank-math/includes/replace-variables/class-basic-variables.php

    on line no: 383 replace the get_current_year() function with the following one:

    public function get_current_year() {
        return date( 'Y', strtotime(' + 543 year') );
    }

    on line no: 355 replace the get_current_date() function with the following one:

    public function get_current_date(){
        setlocale(LC_ALL, "th_TH.UTF-8");
        $dateMonthYear = strftime("%d %B");
        $year = date( 'Y', strtotime(' + 543 year') );
        return $dateMonthYear." ".$year;
    }

    That should change the variable output as per your expectations.

    Please note that if you make these changes, every time the plugin updates the changes will revert back.

    Besides, if you would like to create new variables for both %current_buddhist_year% and %current_buddhist_date%, in a replacement of %currentyear% and %currentdate%, you can try adding the following code snippet to create variables:

    For current_buddhist_year:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    		'current_buddhist_year',
    		[
    		'name'        => esc_html__( 'Current Buddhist Year.', 'rank-math' ),
    		'description' => esc_html__( 'Example: 2566 instead of 2023', 'rank-math' ),
    		'variable'    => 'current_buddhist_year',
    		'example'     => 'Example: 2566 instead of 2023',
    		],
    		'current_buddhist_year_callback'
    	);
    });
    
    function current_buddhist_year_callback(){
        return date( 'Y', strtotime(' + 543 year') );
    }

    For current_buddhist_date:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
        rank_math_register_var_replacement(
            'current_buddhist_date',
            [
            'name'        => esc_html__( 'Current Buddhist Date.', 'rank-math' ),
            'description' => esc_html__( 'Example: 29 มกราคม 2566', 'rank-math' ),
            'variable'    => 'current_buddhist_date',
            'example'     => 'Example: 29 มกราคม 2566',
            ],
            'current_buddhist_date_callback'
        );
    });
    
    function current_buddhist_date_callback(){
        setlocale(LC_ALL, "th_TH.UTF-8");
        $dateMonthYear = strftime("%d %B");
        $year = date( 'Y', strtotime(' + 543 year') );
        return $dateMonthYear." ".$year;
    }

    Note: The changes might not reflect in the editor but you can verify the changes on your page source code.

    Here’s how you can add filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Nih
    Rank Math free

    Thanks for the help, I’ve done it, the results are satisfying.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Nih
    Rank Math free

    Hello,

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

    Thank you.

    Hello,

    Please let us know which implementation you’ve followed. Did you modify the core file of our plugin? If so, and you’ve updated our plugin recently, please make sure to change the core files again as mentioned above.

    If you’ve created a new variable, then we might need to take a closer look at the settings. 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/

    Looking forward to helping you.

    Thank you.

    Nih
    Rank Math free

    Hello,

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

    Thank you.

    Hello,

    I’ve modified the code a bit and replaced the function with the following one:

    function current_buddhist_date_callback(){
        setlocale(LC_ALL, "th_TH.UTF-8");
        $dateMonth = strftime("%d %B");
    	$CE = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
    	$BE = [ "มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม", ];
    	$dateMonthBE = str_replace($CE, $BE, $dateMonth);
        $year = date( 'Y', strtotime(' + 543 year') );
        return $dateMonthBE." ".$year;
    }

    The variable %current_buddhist_date% is now working as expected.

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

    Thank you.

    Nih
    Rank Math free

    Hello,

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

    Thank you.

    Hello,

    Can you please try to use %current_buddhist_date% instead of %currentdate%? You can verify the updated month from your page source code.

    Also, please note that, after changing your meta data, Google may take some time to recrawl and re-index the page in SERPs.

    Let us know how it goes. Looking forward to helping you.

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

The ticket ‘Christian ( Era )’ is closed to new replies.