click count of a certain link in wordpress post

前端 未结 2 1356
故里飘歌
故里飘歌 2021-02-06 13:51

Is it possible to count how many times a certain link in post has been clicked?

(for example purpose, let\'s say that the certain link has an ID named \'bla\')



        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-06 14:01

    It could be done with ajax call that updates post meta field before the link is followed. Example below registers ajax action for users that are not logged in, and increases link_click_counter custom field by 1 on each click. Link must have id attribute countable_link. This is a basic example that works for only one link in post. To use it as a plugin create file like wp-content/plugins/click-counter /click-counter.php and copy-paste example code, or put the code in functions.php inside theme folder. First time the link is clicked, new custom field link_click_counter will be created for that post, and there you can track how many clicks link has.

    HTML:

    download
    

    PHP:

    ID ) ) {
    ?>
        
    
    

提交回复
热议问题