Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to translate the output of counter ? #14

Open
vanpariyar opened this issue Mar 20, 2022 · 1 comment
Open

How to translate the output of counter ? #14

vanpariyar opened this issue Mar 20, 2022 · 1 comment

Comments

@vanpariyar
Copy link
Owner

Thanks for this awesome and simple plugin. I want to translate/str_replace of the output of the counter. How can I do that ? For example, I want to replace “198” with “१९८”. (Latin to Devanagari)

@vanpariyar
Copy link
Owner Author

Thanks for this awesome and simple plugin. I want to translate/str_replace of the output of the counter. How can I do that ? For example, I want to replace “198” with “१९८”. (Latin to Devanagari)

I fiddled around the code and settings near about 3 hours, and finally found the solution to this question. This needs the plugin to be edited. I am sharing my modifications to help anyone wanting to the same thing.

Modify includes/shortcode.php file in this way :

<?php

add_action( 'init', 'wppv_add_custom_shortcode' );
function wppv_add_custom_shortcode() {
	/**
	 * @param $post which is Post id ( Optional )
	 * @author of shortcode Ronak Vanpariya.
	 * @desc Get Post Count For the Blog.
	 */

	function wppv_current_post_view_callback($atts = array() , $content = ''){ 
		$meta_key         = 'entry_views';
		$view_post_meta   = get_post_meta(get_the_ID(), $meta_key, true);
		$view_post_meta = str_replace('1', '', $view_post_meta);
		$view_post_meta = str_replace('2', '', $view_post_meta);
		$view_post_meta = str_replace('3', '', $view_post_meta);
		$view_post_meta = str_replace('4', '', $view_post_meta);
		$view_post_meta = str_replace('5', '', $view_post_meta);
		$view_post_meta = str_replace('6', '', $view_post_meta);
		$view_post_meta = str_replace('7', '', $view_post_meta);
		$view_post_meta = str_replace('8', '', $view_post_meta);
		$view_post_meta = str_replace('9', '', $view_post_meta);
		$view_post_meta = str_replace('0', '', $view_post_meta); 
		return $view_post_meta;
	}
	if(!shortcode_exists( 'WPPV-TOTAL-VIEWS' )){
		add_shortcode( 'WPPV-TOTAL-VIEWS', 'wppv_current_post_view_callback' );
	}	
}

Expand
After the line
$view_post_meta = get_post_meta(get_the_ID(), $meta_key, true);
I entered the str_replace lines, and finally return $view_post_meta;

You can replace the Devanagari Numerals to any script ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant