Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more

How to 301 redirect from url with post id to permalink with post name (slug)?

yes, it is possible. add a template_redirect hook handler: add_filter(‘template_redirect’, ‘redirect_post_to_canonical_url’); function redirect_post_to_canonical_url(): void { if (!is_single()) { // do not redirect nothing else except posts return; } $canonicalLocation = get_permalink(); $requestUri = $_SERVER[‘REQUEST_URI’]; $currentLocation = home_url(“https://wordpress.stackexchange.com/”) . substr($requestUri, 1); if ($currentLocation === $canonicalLocation) { // prevent from infinite redirect loop return; } wp_redirect($canonicalLocation, 301); … Read more

Top tags with minimum number of posts

I found a solution!: $term_ids = $wpdb->get_col(” SELECT term_id FROM $wpdb->term_taxonomy INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id WHERE DATE_SUB(CURDATE(), INTERVAL 1 DAY) <= $wpdb->posts.post_date” ); $tags = get_tags(array( ‘orderby’ => ‘count’, ‘order’ => ‘DESC’, ‘number’ => ’10’, // <– maximum number of tags ‘include’ => $term_ids, ‘fields’ => ‘ids’ … Read more

How to center all text body in single.php at once?

There is probably some CSS you can add via Additional CSS (in Theme CUstomization) that you could use. Use the Inspector tool of your browser (F12) to see the CSS ‘class’ element used in the content. If the class is called ‘the_content’, then add this to your Additional CSS: .the_content{text-align:center !important;} You might need this, … Read more

How to create page with post content in it?

You might get away with shortcodes: add_shortcode(‘title’, function ($atts, $content = null) { $atts = shortcode_atts([ ‘id’ => null, ], $atts); $title=””; if (!empty($atts[‘id’])) { $title = get_the_title($atts[‘id’]); } return $title; }); add_shortcode(‘content’, function ($atts, $content = null) { $atts = shortcode_atts([ ‘id’ => null, ], $atts); $content=””; if (!empty($atts[‘id’])) { $post = get_post($atts[‘id’]); // … Read more

Strange behaviour in WordPress admin

I’d first make sure that everything is updated: WP, themes, plugins. Then I’d look at the plugin’s WP page and see how long it’s been since they have been updated. You might have some old plugins that could be causing problems, like maybe they are using old JS. I’d also look at the page source … Read more