Code for unique user visit count on every page WordPress

My guess is that the user must be logged in? If that is the case you can simply store the page hits as metadata doing something like this: add_shortcode(‘pagehits’, ‘showPageHits’); function showPageHits($attributes) { /** @var \WP_Query $wp_query */ global $wp_query; $page = $wp_query->get_queried_object_id(); if (is_user_logged_in()) { $user = wp_get_current_user()->ID; $meta = get_user_meta($user, ‘pagehits’, true) ?: … Read more

Prevent post from being published and show error

The argument syntax in your strpos() call is such that it’s testing the content for the literal string “$words” instead of the content of the $words variable. publish_post action hooks do not directly receive a post’s content as an argument. However if you use the provided arguments as detailed by the documentation, it is not … Read more