0x1998 - MANAGER
Düzenlenen Dosya: functions.php
<?php // ================================ // Child Theme - JetEngine Legacy Version Fix // ================================ // بارگذاری استایل قالب والد function hello_elementor_child_enqueue_styles() { wp_enqueue_style( 'hello-elementor-parent-style', get_template_directory_uri() . '/style.css' ); } add_action( 'wp_enqueue_scripts', 'hello_elementor_child_enqueue_styles' ); /* =============================== * NIMOOLI SIMPLE POST VIEWS * Every refresh = +1 view * Single Meta | No JS | No ESI * =============================== */ /** * دریافت تعداد بازدید */ function nimooli_get_post_views( $post_id = null ) { if ( ! $post_id ) { $post_id = get_the_ID(); } if ( ! $post_id ) { return 0; } $views = get_post_meta( $post_id, 'post_views', true ); return ( $views !== '' ) ? (int) $views : 0; } /** * افزایش بازدید * هر بار لود صفحه = +1 */ function nimooli_increase_post_views() { if ( ! is_singular('post') ) { return; } $post_id = get_the_ID(); if ( ! $post_id ) { return; } $views = nimooli_get_post_views( $post_id ) + 1; update_post_meta( $post_id, 'post_views', $views ); } add_action( 'template_redirect', 'nimooli_increase_post_views', 0 ); /** * شورتکد نمایش بازدید * استفاده: * [post_views] * [post_views id="123"] */ add_shortcode( 'post_views', function( $atts ) { $atts = shortcode_atts( [ 'id' => get_the_ID(), ], $atts ); $post_id = (int) $atts['id']; if ( ! $post_id ) { return '0'; } return nimooli_get_post_views( $post_id ); }); /** * Remove website field from wp comment form */ add_filter('comment_form_default_fields', function ($fields) { if (isset($fields['url'])) { unset($fields['url']); } return $fields; }); // حذف لیزی لود از تصویر شاخص ادامه مطلب add_filter('wp_get_attachment_image_attributes', function ($attr, $attachment, $size) { if (is_singular() && has_post_thumbnail()) { $thumb_id = get_post_thumbnail_id(); if ($attachment->ID === $thumb_id) { $attr['loading'] = 'eager'; $attr['fetchpriority'] = 'high'; } } return $attr; }, 10, 3); add_filter('wp_get_attachment_image_attributes', function ($attr, $attachment, $size) { // فقط صفحه خانه، فرانت یا آرشیو if (!is_home() && !is_front_page() && !is_archive()) { return $attr; } static $done = false; if ($done) { return $attr; } // فقط در لوپ اصلی if (!in_the_loop()) { return $attr; } $attr['loading'] = 'eager'; $attr['fetchpriority'] = 'high'; $done = true; return $attr; }, 10, 3); // فیلتر کردن همه نظرات: فقط تایید شدهها add_action( 'pre_get_comments', function( $query ) { if( is_admin() ) return; // فقط فرانتاند $query->query_vars['status'] = 'approve'; // فقط تایید شده }); /** * Clean URLs - combines both space to hyphen and .html removal */ function clean_urls_redirect() { if (!is_admin() && is_404()) { $requested_url = $_SERVER['REQUEST_URI']; $decoded_url = urldecode($requested_url); $new_url = $decoded_url; // Convert spaces and %20 to hyphens if (strpos($decoded_url, ' ') !== false || strpos($requested_url, '%20') !== false) { $new_url = str_replace(array(' ', '%20'), '-', $decoded_url); $new_url = preg_replace('/-+/', '-', $new_url); } // Remove .html extension $new_url = preg_replace('/\.html$/', '', $new_url); // Only redirect if URL was modified if ($new_url !== $decoded_url) { wp_redirect(home_url($new_url), 301); exit; } } } add_action('template_redirect', 'clean_urls_redirect', 1); add_action('template_redirect', 'custom_forum_redirects'); function custom_forum_redirects() { $request_uri = strtolower($_SERVER['REQUEST_URI']); // ریدایرکت تمام موارد /forum/ یا /Forum/ به صفحه اصلی if (strpos($request_uri, '/forum/') === 0 || strpos($request_uri, '/Forum/') === 0) { wp_redirect(home_url('/'), 301); exit; } // ریدایرکت /pages/* به /page/* if (preg_match('#^/pages/(.*)#', $_SERVER['REQUEST_URI'], $matches)) { wp_redirect(home_url('/page/' . $matches[1]), 301); exit; } }
geri dön