Created
July 4, 2024 12:34
-
-
Save larbous/ae2d9490998e40baf9da2923b9f2c84c to your computer and use it in GitHub Desktop.
Contador de Views para WordPress Posts e CPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Desenvolvido por Dante Testa + ASK Jarvis*/ | |
/*Coloque esse código no functions.php do seu tema */ | |
/*https://www.youtube.com/watch?v=NKxyNbJbee4 */ | |
function views_shortcode( $atts ) { | |
$a = shortcode_atts( array( | |
'print' => '0', | |
'count' => '0', | |
), $atts ); | |
$print = $a['print']; | |
$count = $a['count']; | |
if($count == 1){ | |
$views = get_post_meta(get_the_ID(), 'views', true); | |
$views++; | |
update_post_meta(get_the_ID(), 'views', $views); | |
} | |
if($print == 1){ | |
$views = get_post_meta(get_the_ID(), 'views', true); | |
return $views; | |
} | |
} | |
add_shortcode( 'views', 'views_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment