Support » Plugin: WP-PostViews » Adding code customisation

  • Resolved gates


    I always edited the plugin to get a dot instead of a comma between thousands, because that’s how we roll in Europe: thousand is not 1,000 but 1.000. (I guess that using another language for the WP installation solves this, but I’d like to keep the backend in English). So I go to line 197 and change it this
    $output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix;
    $output = $prefix.str_replace('%VIEW_COUNT%', number_format($post_views, 0, ',', '.'), $views_options['template']).$postfix;

    But then saw this post about adding code customisation in WordPress the right way. How should I add this in my custom plugin? I’m afraid to screw something up.

    add_filter( 'the_views', 'customisation_of_the_views' );
    function customisation_of_the_views( /* keep this empty or copy the same code from the plugin? */) {
        // How to swap my customisation in line 197

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Lester Chan


    The filter will not work because both backend and front end will use it. If you change the language, it will be “.”

    it is not possible to have both “.” and “,” without some modifications to the plugin. You will probably have to duplicate the the_views function to the_views_2 or something and in change it to call the_views_2

    Aha… thanks for letting me know. So even if I only want to change the output in the front-end it won’t work? I don’t mind the commas in the back end.

    Edit: I see you’ve updated your post. About duplicating the function; I’m afraid that something like that increases the chance to break something in a future update. So I’ll just use the method in my first post.

    Plugin Author Lester Chan


    Nope, that is because the function is called by both front end and back end.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding code customisation’ is closed to new replies.