Choosing the best dentist for implant treatment is one of the most important decisions a patient can make when restoring missing teeth. Dental implants are considered one of the most advanced and long-lasting solutions in modern dentistry because they replace both the tooth root and the visible crown. However, the success of treatment depends heavily on selecting the best dentist for implant procedures. Patients who invest time in researching qualifications, technology, experience, and patient satisfaction are more likely to achieve comfortable, natural-looking, and durable results. 😊
The best dentist for implant treatment focuses not only on replacing missing teeth but also on improving oral health, chewing function, facial aesthetics, and confidence. A skilled implant dentist carefully evaluates jawbone density, gum health, bite alignment, and overall dental condition before creating a personalized treatment plan. Every patient has different needs, and the best dentist for implant care understands how to tailor the procedure to each individual.
Dental implants are titanium posts surgically inserted into the jawbone to support crowns, bridges, or dentures. Over time, the implant fuses with the bone through a process called osseointegration. This creates a stable foundation that feels similar to a natural tooth root. The best dentist for implant procedures uses advanced imaging systems and digital planning tools to ensure precise implant placement and long-term stability.
One of the main reasons people search for the best dentist for implant treatment is the desire for a permanent and natural-looking smile. Missing teeth can affect self-esteem, speech, and daily comfort. Patients often feel embarrassed when smiling or speaking in social situations. Implant dentistry can restore confidence by creating a strong and attractive smile that closely resembles natural teeth. 😁
When selecting the best dentist for implant care, patients should evaluate education and clinical experience. Implant dentistry requires specialized training beyond general dental education. A highly qualified implant dentist usually attends advanced courses, international seminars, and continuing education programs focused on oral surgery and prosthetic restoration. Experience matters because implant procedures involve both surgical and cosmetic precision.
Technology also plays a major role in determining the best dentist for implant treatment. Modern clinics often use 3D cone beam computed tomography (CBCT) scans, digital impressions, guided implant surgery, and CAD/CAM restorations. These technologies improve treatment accuracy, reduce discomfort, and shorten recovery time. Patients should look for clinics that invest in modern dental innovations because this often reflects a commitment to high-quality care.
Another important factor when choosing the best dentist for implant services is patient communication. A trustworthy implant dentist explains every stage of treatment clearly and honestly. Patients should fully understand treatment timelines, healing periods, possible risks, and expected outcomes. Transparent communication builds trust and reduces anxiety throughout the implant journey.
The best dentist for implant procedures also prioritizes patient safety and hygiene. Implant surgery must be performed in a sterile clinical environment using high-quality materials. Reputable clinics follow international sterilization protocols and use certified implant brands known for durability and clinical success. Patients should never hesitate to ask questions about implant systems and safety standards.
Cost is another reason many patients research the best dentist for implant treatment carefully. Implant prices can vary depending on the number of implants, bone grafting needs, materials, and clinic location. While affordability is important, patients should avoid choosing treatment solely based on low pricing. Extremely cheap implant procedures may involve lower-quality materials or limited clinical experience. The best dentist for implant care focuses on long-term value rather than short-term savings.
Patients traveling internationally for implant treatment often compare clinics in different countries. Dental tourism has become increasingly popular because many clinics offer advanced care at competitive prices. Countries with experienced implant specialists and modern facilities attract thousands of international patients every year. Before traveling, patients should research reviews, before-and-after photos, certifications, and communication quality to identify the best dentist for implant treatment abroad.
Reviews and testimonials can help patients evaluate the best dentist for implant services. Positive patient experiences often highlight professionalism, comfort, successful healing, and natural-looking outcomes. Online reviews may also provide insight into clinic cleanliness, staff friendliness, appointment scheduling, and post-treatment support.
In many cases, the best dentist for implant treatment involves a multidisciplinary approach. Implant procedures may require collaboration between oral surgeons, prosthodontists, periodontists, and cosmetic dentists. Teamwork ensures that each part of treatment is handled by experienced professionals who specialize in different aspects of oral rehabilitation.
Patients should also understand the importance of aftercare when working with the best dentist for implant provider. Dental implants require proper oral hygiene and regular dental checkups to maintain long-term success. Brushing, flossing, professional cleanings, and avoiding harmful habits like smoking can significantly increase implant lifespan. Many implants can last decades when maintained correctly. 🦷
The best dentist for implant treatment often provides comprehensive consultations that include digital smile analysis, treatment simulations, and personalized recommendations. This helps patients visualize potential outcomes and feel more confident before beginning treatment. A patient-centered clinic focuses on comfort, education, and long-term satisfaction rather than rushing the process.
Patients looking for expert implant consultation and personalized dental care can visit the Redent Klinik Contact Page for additional information about treatment options and professional support.
For trusted oral health information and implant dentistry standards, patients can also review resources provided by the American Dental Association.
Ultimately, selecting the best dentist for implant procedures requires careful research, patience, and attention to detail. A successful implant treatment can dramatically improve quality of life, confidence, and oral health for many years. By focusing on expertise, technology, communication, and patient satisfaction, individuals can make informed decisions and achieve healthy, beautiful smiles that feel completely natural. ✨
LSI keywords naturally associated with the best dentist for implant treatment include implant specialist, cosmetic dental implants, tooth replacement solutions, oral rehabilitation, implant-supported crowns, and advanced implant dentistry. These related terms help patients better understand the complete scope of implant care and modern restorative dentistry.
How to Choose the Best Dentist for Implant Treatment
Finding the best dentist for implant treatment can completely transform a patient’s oral health, confidence, and quality of life. Dental implants are considered one of the most effective long-term solutions for missing teeth because they closely mimic natural teeth in both appearance and function. However, successful treatment depends heavily on selecting the best dentist for implant procedures. Patients who carefully evaluate qualifications, technology, patient reviews, communication style, and treatment planning are more likely to achieve durable and aesthetically pleasing results. 😊
Many people assume all dentists provide the same level of implant care, but implant dentistry is a specialized field that requires advanced training and clinical expertise. The best dentist for implant procedures understands surgical precision, restorative planning, bone integration, gum aesthetics, and bite function. Since implants are designed to last for many years, choosing the right dental professional is extremely important.
Why Choosing the Right Implant Dentist Matters
The best dentist for implant treatment does much more than simply place a titanium post into the jawbone. Implant dentistry requires detailed diagnostics, careful treatment planning, and long-term patient monitoring. A poorly placed implant can lead to discomfort, bone loss, gum complications, or implant failure. On the other hand, a properly placed implant by the best dentist for implant care can function naturally for decades.
Patients often seek implant treatment after losing teeth because of decay, trauma, periodontal disease, or aging. Missing teeth can negatively affect speech, chewing ability, facial appearance, and emotional confidence. The best dentist for implant solutions restores these functions while preserving jawbone structure and supporting overall oral health.
Education and Specialized Implant Training
One of the most important factors when choosing the best dentist for implant care is education. Implant dentistry involves advanced procedures that go beyond general dental training. Highly qualified implant dentists usually complete continuing education courses, oral surgery training, implant certification programs, and international workshops.
Advanced Clinical Experience
Experience significantly influences implant success rates. The best dentist for implant treatment often has years of practical experience handling simple and complex implant cases. Experienced implant dentists know how to manage patients with bone loss, gum disease, sinus complications, or multiple missing teeth.
Patients should feel comfortable asking how many implant procedures the dentist performs annually. High-volume implant providers usually have greater familiarity with surgical techniques and restorative accuracy.
Professional Memberships
The best dentist for implant providers frequently belong to respected dental organizations and implant associations. Memberships demonstrate commitment to professional standards and continuing education. Patients may also review educational resources from the American Dental Association to better understand implant care standards.
Modern Technology Used by the Best Dentist for Implant Procedures
Technology plays a major role in implant dentistry success. The best dentist for implant treatment uses advanced digital systems to improve precision, comfort, and long-term outcomes.
3D Imaging and Digital Scans
Modern implant clinics often use cone beam computed tomography (CBCT) scans to evaluate jawbone density and anatomical structures. These scans help the best dentist for implant surgery identify nerves, sinus cavities, and bone volume before treatment begins.
Digital impressions also improve patient comfort by eliminating traditional messy molds. These digital systems increase accuracy and reduce the risk of restoration errors.
Guided Implant Surgery
The best dentist for implant procedures may include computer-guided implant placement. Guided surgery uses digital planning software and custom surgical guides to position implants precisely. This often leads to faster healing, minimal discomfort, and better cosmetic outcomes. 🦷
Patient Reviews and Before-and-After Results
Reviews are valuable when searching for the best dentist for implant treatment. Positive patient experiences often reveal important details about professionalism, cleanliness, communication, comfort, and long-term results.
Patients should carefully examine before-and-after photos to evaluate smile aesthetics and implant quality. The best dentist for implant procedures produce natural-looking restorations that blend seamlessly with surrounding teeth.
Communication and Personalized Treatment Planning
The best dentist for implant treatment always begins with detailed consultation and personalized planning. Every patient has unique oral health needs, bone conditions, and aesthetic expectations. A trustworthy implant dentist explains all treatment options clearly and answers questions honestly.
Clear Treatment Explanations
Patients should fully understand the timeline, healing stages, implant materials, and possible risks before starting treatment. The best dentist for implant care prioritizes patient education and transparency.
Comfort and Anxiety Management
Dental anxiety is common among implant patients. The best dentist for implant procedures often include sedation options, gentle surgical techniques, and supportive patient care to reduce fear and stress during treatment.
Understanding Implant Costs and Value
Cost is another major factor when selecting the best dentist for implant care. Implant prices vary depending on implant brand, clinic location, restoration type, bone grafting needs, and treatment complexity.
Estimated Implant Costs
Typical single dental implant costs may include:
- Consultation and diagnostics: $100–$500
- Single implant placement: $1,000–$3,000
- Abutment and crown: $500–$2,000
- Bone grafting if needed: $300–$3,000
Although low-cost offers may seem attractive, patients should prioritize quality and expertise over cheap pricing. The best dentist for implant treatment focuses on long-term success, safety, and durable materials.
Importance of Long-Term Aftercare
The best dentist for implant care continues even after surgery is completed. Long-term maintenance is essential for implant success. Patients should attend routine checkups, maintain excellent oral hygiene, and follow professional cleaning recommendations.
Smoking, poor oral hygiene, and untreated gum disease can reduce implant lifespan. The best dentist for implant treatment includes ongoing patient education about implant maintenance and healthy habits.
Dental Tourism and International Implant Clinics
Many international patients search for the best dentist for implant procedures abroad because of affordable pricing and advanced treatment options. Countries with modern dental clinics and experienced implant specialists attract patients seeking high-quality care at lower costs.
Before choosing an overseas clinic, patients should evaluate certifications, patient reviews, technology, communication quality, and transparency. Clinics that provide detailed consultations and clear treatment plans often demonstrate higher professional standards.
Patients interested in professional consultation and personalized implant planning can visit the Redent Klinik Contact Page for additional support and treatment information.
Ultimately, selecting the best dentist for implant treatment requires careful research, patience, and attention to detail. Patients who prioritize experience, technology, communication, and long-term care are more likely to enjoy stable, attractive, and comfortable implant results for many years. ✨
‘img’,
‘href’ => $image[0],
‘srcset’ => wp_get_attachment_image_srcset($thumb_id, ‘full’),
‘sizes’ => ‘(max-width: 767px) calc(100vw – 30px), (max-width: 1199px) 720px, 860px’,
‘candidate’ => ‘single-featured’,
);
}
} elseif (redent_sitewide_speed_should_preload_titlebar_server_side()) {
$candidate = array(
‘type’ => ‘background’,
‘href’ => home_url(‘/wp-content/uploads/2021/08/titlebg.jpg.webp’),
‘candidate’ => ‘titlebar’,
);
}
if ($candidate) {
echo redent_sitewide_speed_build_preload_link($candidate) . “\n”;
}
}
function redent_sitewide_speed_should_preload_titlebar_server_side()
{
$path = redent_sitewide_speed_request_path();
if ($path === ‘/’ || preg_match(‘#/(home|anasayfa)/?$#i’, $path)) {
return false;
}
if (function_exists(‘is_front_page’) && is_front_page()) {
return false;
}
if (function_exists(‘is_singular’) && is_singular(‘post’)) {
return false;
}
if (function_exists(‘is_home’) && is_home()) {
return true;
}
if (function_exists(‘is_archive’) && is_archive()) {
return true;
}
if (function_exists(‘is_search’) && is_search()) {
return true;
}
if (function_exists(‘is_page’) && is_page()) {
return true;
}
return false;
}
add_action(‘wp_head’, ‘redent_sitewide_speed_print_critical_css’, 1);
function redent_sitewide_speed_print_critical_css()
{
if (!redent_sitewide_speed_is_frontend()) {
return;
}
?>
‘) === false || stripos($html, ‘/i’, $preload . “\n“, $html, 1);
}
}
$html = redent_sitewide_speed_stabilize_featured_wrapper($html);
$html = redent_sitewide_speed_normalize_titlebar_background_url($html);
$html = redent_sitewide_speed_defer_blocking_css_links($html);
return redent_sitewide_speed_remove_home_only_delayed_css_loader_off_home($html);
}
function redent_sitewide_speed_defer_blocking_css_links($html)
{
if (stripos($html, ‘]*\brel=([“\’])stylesheet\1[^>]*>/i’, ‘redent_sitewide_speed_defer_blocking_css_link_match’, $html);
}
function redent_sitewide_speed_defer_blocking_css_link_match($match)
{
$tag = $match[0];
if (stripos($tag, ‘data-redent-sitewide-css-defer’) !== false || stripos($tag, ‘data-redent-home-speed-noncritical-css-defer’) !== false) {
return $tag;
}
if (preg_match(‘/\bmedia=([“\’])print\1/i’, $tag)) {
return $tag;
}
$id = redent_sitewide_speed_get_attr($tag, ‘id’);
$href = redent_sitewide_speed_get_attr($tag, ‘href’);
$normalized_id = preg_replace(‘/-css$/’, ”, $id);
$defer_handles = array(
‘bootstrap’,
‘bootstrap-theme’,
‘brivona-base-style’,
‘brivona-main-style’,
‘brivona-responsive-style’,
‘brivona-last-checkpoint’,
‘brivona-servicebox-animation’,
‘contact-form-7’,
‘eztoc’,
‘font-awesome’,
‘flexslider’,
‘js_composer_front’,
‘megamenu’,
‘multi-columns-row’,
‘prettyphoto’,
‘rs-plugin-settings’,
‘themetechmount-brivona-extra-icons’,
‘themify’,
‘tm-brivona-icons’,
‘wp-block-library’,
);
$is_litespeed_css = strpos($href, ‘/wp-content/litespeed/css/’) !== false;
if (!$is_litespeed_css && !in_array($normalized_id, $defer_handles, true)) {
return $tag;
}
if (redent_sitewide_speed_is_real_home_path() && in_array($normalized_id, array(‘brivona-main-style’, ‘brivona-base-style’, ‘bootstrap’), true)) {
return $tag;
}
$original = preg_replace(‘/\s+onload=([“\’]).*?\1/i’, ”, $tag);
$original = preg_replace(‘/\s+media=([“\’]).*?\1/i’, ”, $original);
$original = preg_replace(‘/\s+data-redent-sitewide-css-defer=([“\’]).*?\1/i’, ”, $original);
$original = preg_replace(‘/\s*\/?>$/’, ” media=’all’ />”, $original);
$deferred = preg_replace(‘/\s+onload=([“\’]).*?\1/i’, ”, $tag);
$deferred = preg_replace(‘/\s+media=([“\’]).*?\1/i’, ”, $deferred);
$deferred = preg_replace(‘/\s*\/?>$/’, ” media=’print’ onload=\”this.onload=null;this.media=’all’\” data-redent-sitewide-css-defer=’1′ />”, $deferred);
return $deferred . ‘‘;
}
function redent_sitewide_speed_is_real_home_path()
{
$path = trim(redent_sitewide_speed_request_path(), ‘/’);
if ($path === ”) {
return true;
}
return (bool) preg_match(‘#^(?:[a-z]{2}/)?(?:home|anasayfa)$#i’, $path);
}
function redent_sitewide_speed_remove_home_only_delayed_css_loader_off_home($html)
{
if (redent_sitewide_speed_is_real_home_path()) {
return $html;
}
$html = preg_replace(
‘#\s*#is’,
”,
$html
);
$html = preg_replace(
‘#]*(?:\bid=([“\’])redent-home-inline-css-family-all-lowrisk-v1-marker\1|\bname=([“\’])redent-home-inline-css-family-all-lowrisk-v1\2))[^>]*>\s*#i’,
”,
$html
);
return $html;
}
function redent_sitewide_speed_normalize_titlebar_background_url($html)
{
if (stripos($html, ‘titlebg.jpg’) === false || redent_sitewide_speed_is_real_home_path()) {
return $html;
}
return preg_replace(
‘#https://www\.redentklinik\.com/wp-content/uploads/2021/08/titlebg\.jpg(?!\.webp)#i’,
‘https://www.redentklinik.com/wp-content/uploads/2021/08/titlebg.jpg.webp’,
$html
);
}
function redent_sitewide_speed_remove_previous_lcp_preload($html)
{
return preg_replace(
‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>\s*#i’,
”,
$html
);
}
function redent_sitewide_speed_existing_preload_matches($html, $candidate)
{
if (empty($candidate[‘href’])) {
return false;
}
if (!preg_match(‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>#i’, $html, $match)) {
return false;
}
$href = redent_sitewide_speed_get_attr($match[0], ‘href’);
return redent_sitewide_speed_normalize_url($href) === redent_sitewide_speed_normalize_url($candidate[‘href’]);
}
function redent_sitewide_speed_choose_lcp_candidate($html)
{
$is_single_post = redent_sitewide_speed_html_is_single_post($html);
if (!$is_single_post) {
$titlebar = redent_sitewide_speed_extract_titlebar_background($html);
if ($titlebar) {
return array(
‘type’ => ‘background’,
‘href’ => $titlebar,
‘candidate’ => ‘titlebar’,
);
}
}
if ($is_single_post) {
$featured = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($featured) {
$featured[‘candidate’] = ‘single-featured’;
return $featured;
}
}
$archive = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($archive) {
$archive[‘candidate’] = ‘archive-first-card’;
return $archive;
}
$first = redent_sitewide_speed_extract_first_meaningful_img($html);
if ($first) {
$first[‘candidate’] = ‘first-meaningful-img’;
}
return $first;
}
function redent_sitewide_speed_html_is_single_post($html)
{
if (preg_match(‘/
if (preg_match(‘/(?:^|\s)single-post(?:\s|$)/’, $body[2])) {
return true;
}
}
return (bool) preg_match(‘/
}
function redent_sitewide_speed_extract_titlebar_background($html)
{
if (stripos($html, ‘tm-titlebar-wrapper’) === false) {
return ”;
}
$urls = array();
if (preg_match_all(‘/\.tm-titlebar-wrapper[^{]*\{[^}]*\}/i’, $html, $rules)) {
foreach ($rules[0] as $rule) {
if (preg_match_all(‘/url\(([“\’]?)([^)”\’]+\.(?:webp|jpe?g|png|avif))(?:\1)\)/i’, $rule, $matches)) {
foreach ($matches[2] as $url) {
$urls[] = redent_sitewide_speed_normalize_url($url);
}
}
}
}
$urls = array_values(array_filter(array_unique($urls)));
if (!$urls) {
return ”;
}
foreach (array_reverse($urls) as $url) {
if (preg_match(‘/\.webp(?:\?|$)/i’, $url)) {
return $url;
}
}
return end($urls);
}
function redent_sitewide_speed_extract_first_img($html, $pattern)
{
if (!preg_match($pattern, $html, $match)) {
return null;
}
$tag = $match[0];
if (preg_match(‘/]*>$/is’, $tag, $img_match)) {
return redent_sitewide_speed_img_candidate_from_tag($img_match[0]);
}
return null;
}
function redent_sitewide_speed_extract_first_meaningful_img($html)
{
if (!preg_match_all(‘/]*>/i’, $html, $matches)) {
return null;
}
foreach ($matches[0] as $tag) {
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if (preg_match(‘/(?:logo|avatar|icon|emoji|favicon)/i’, $class)) {
continue;
}
$src = redent_sitewide_speed_img_src($tag);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
continue;
}
$width = (int) redent_sitewide_speed_get_attr($tag, ‘width’);
$height = (int) redent_sitewide_speed_get_attr($tag, ‘height’);
if (($width && $width < 180) || ($height && $height < 120)) {
continue;
}return redent_sitewide_speed_img_candidate_from_tag($tag);
}return null;
}function redent_sitewide_speed_img_candidate_from_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src === '') {
return null;
}$srcset = redent_sitewide_speed_get_attr($tag, 'srcset');
if ($srcset === '') {
$srcset = redent_sitewide_speed_get_attr($tag, 'data-srcset');
}$sizes = redent_sitewide_speed_get_attr($tag, 'sizes');
if ($sizes === '') {
$sizes = redent_sitewide_speed_get_attr($tag, 'data-sizes');
}return array(
'type' => ‘img’,
‘href’ => redent_sitewide_speed_normalize_url($src),
‘srcset’ => $srcset,
‘sizes’ => $sizes,
‘tag’ => $tag,
);
}
function redent_sitewide_speed_img_src($tag)
{
$src = redent_sitewide_speed_get_attr($tag, ‘src’);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
$src = redent_sitewide_speed_get_attr($tag, ‘data-src’);
}
return redent_sitewide_speed_normalize_url($src);
}
function redent_sitewide_speed_get_attr($tag, $attr)
{
$attr = preg_quote($attr, ‘/’);
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([“\’])(.*?)\1/is’, $tag, $match)) {
return html_entity_decode(trim($match[2]), ENT_QUOTES);
}
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([^\s>]+)/is’, $tag, $match)) {
return html_entity_decode(trim($match[1], “\”‘”), ENT_QUOTES);
}
return ”;
}
function redent_sitewide_speed_normalize_url($url)
{
$url = trim(html_entity_decode((string) $url, ENT_QUOTES), ” \t\n\r\0\x0B\”‘”);
if ($url === ”) {
return ”;
}
if (strpos($url, ‘//’) === 0) {
return ‘https:’ . $url;
}
if (strpos($url, ‘/’) === 0) {
return home_url($url);
}
return $url;
}
function redent_sitewide_speed_build_preload_link($candidate)
{
$href = redent_sitewide_speed_normalize_url($candidate[‘href’]);
if ($href === ”) {
return ”;
}
$attrs = array(
‘rel’ => ‘preload’,
‘as’ => ‘image’,
‘href’ => esc_url($href),
‘fetchpriority’ => ‘high’,
‘data-redent-lcp-preload’ => ‘1’,
‘data-redent-lcp-candidate’ => isset($candidate[‘candidate’]) ? sanitize_key($candidate[‘candidate’]) : ‘image’,
);
if (!empty($candidate[‘srcset’])) {
$attrs[‘imagesrcset’] = esc_attr($candidate[‘srcset’]);
}
if (!empty($candidate[‘sizes’])) {
$attrs[‘imagesizes’] = esc_attr($candidate[‘sizes’]);
}
$html = ‘ $value) {
$html .= ‘ ‘ . $name . ‘=”‘ . $value . ‘”‘;
}
return $html . ‘ />’;
}
function redent_sitewide_speed_prioritize_img_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src !== ” && redent_sitewide_speed_get_attr($tag, ‘src’) !== $src) {
if (preg_match(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, ‘ src=”‘ . esc_url($src) . ‘”‘, $tag, 1);
} else {
$tag = preg_replace(‘/)/is’, ”, $tag);
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if ($class !== ” && strpos($class, ‘redent-lcp-image’) === false) {
$tag = preg_replace(‘/\sclass\s*=\s*([“\’])(.*?)\1/is’, ‘ class=”$2 redent-lcp-image”‘, $tag, 1);
} elseif ($class === ”) {
$tag = preg_replace(‘/ 0 && $height > 0 && stripos($tag, ‘aspect-ratio’) === false) {
$ratio = $width . ‘ / ‘ . $height;
if (preg_match(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, ‘ style=”$2; aspect-ratio: ‘ . esc_attr($ratio) . ‘; height: auto;”‘, $tag, 1);
} else {
$tag = preg_replace(‘/]*class=([“\’])(?=[^”\’]*\btm-featured-outer-wrapper\b)(?=[^”\’]*\btm-post-featured-outer-wrapper\b)([^”\’]*)\2[^>]*>)(.{0,1200}?
]*\bwp-post-image\b[^>]*>)#is’,
‘redent_sitewide_speed_stabilize_featured_wrapper_match’,
$html
);
}
function redent_sitewide_speed_stabilize_featured_wrapper_match($match)
{
$open = $match[1];
$rest = $match[4];
if (strpos($open, ‘redent-cls-reserved-media’) === false) {
$open = preg_replace(‘/\sclass=([“\’])(.*?)\1/is’, ‘ class=”$2 redent-cls-reserved-media”‘, $open, 1);
}
if (stripos($open, ‘aspect-ratio’) === false && preg_match(‘/]*>/i’, $rest, $img)) {
$width = (int) redent_sitewide_speed_get_attr($img[0], ‘width’);
$height = (int) redent_sitewide_speed_get_attr($img[0], ‘height’);
if ($width > 0 && $height > 0) {
$style = ‘–redent-featured-ratio: ‘ . $width . ‘ / ‘ . $height . ‘; aspect-ratio: ‘ . $width . ‘ / ‘ . $height . ‘;’;
if (preg_match(‘/\sstyle=([“\’])(.*?)\1/is’, $open)) {
$open = preg_replace(‘/\sstyle=([“\’])(.*?)\1/is’, ‘ style=”$2; ‘ . esc_attr($style) . ‘”‘, $open, 1);
} else {
$open = preg_replace(‘/>$/’, ‘ style=”‘ . esc_attr($style) . ‘”>’, $open, 1);
}
}
}
return $open . $rest;
}
function redent_sitewide_speed_replace_once($search, $replace, $subject)
{
$pos = strpos($subject, $search);
if ($pos === false) {
return $subject;
}
return substr_replace($subject, $replace, $pos, strlen($search));
}
add_action(‘wp_enqueue_scripts’, ‘redent_sitewide_speed_control_jquery’, 1000);
function redent_sitewide_speed_control_jquery()
{
if (!redent_sitewide_speed_is_frontend()) {
return;
}
global $wp_scripts;
if (!($wp_scripts instanceof WP_Scripts)) {
return;
}
foreach (array(‘jquery’, ‘jquery-core’, ‘jquery-migrate’) as $handle) {
if (isset($wp_scripts->registered[$handle])) {
$wp_scripts->add_data($handle, ‘group’, 1);
$wp_scripts->add_data($handle, ‘strategy’, ‘defer’);
}
}
}
add_filter(‘script_loader_tag’, ‘redent_sitewide_speed_defer_jquery_family_tag’, 20, 3);
function redent_sitewide_speed_defer_jquery_family_tag($tag, $handle, $src)
{
if (!redent_sitewide_speed_is_frontend()) {
return $tag;
}
if (!redent_sitewide_speed_script_depends_on_jquery($handle)) {
return $tag;
}
if (stripos($tag, ‘ defer’) !== false || stripos($tag, ‘ async’) !== false || stripos($tag, ‘type=”module”‘) !== false) {
return $tag;
}
return preg_replace(‘/\s*#is’,
”,
$html
);
$html = preg_replace(
‘#]*(?:\bid=([“\’])redent-home-inline-css-family-all-lowrisk-v1-marker\1|\bname=([“\’])redent-home-inline-css-family-all-lowrisk-v1\2))[^>]*>\s*#i’,
”,
$html
);
return $html;
}
function redent_sitewide_speed_normalize_titlebar_background_url($html)
{
if (stripos($html, ‘titlebg.jpg’) === false || redent_sitewide_speed_is_real_home_path()) {
return $html;
}
return preg_replace(
‘#https://www\.redentklinik\.com/wp-content/uploads/2021/08/titlebg\.jpg(?!\.webp)#i’,
‘https://www.redentklinik.com/wp-content/uploads/2021/08/titlebg.jpg.webp’,
$html
);
}
function redent_sitewide_speed_remove_previous_lcp_preload($html)
{
return preg_replace(
‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>\s*#i’,
”,
$html
);
}
function redent_sitewide_speed_existing_preload_matches($html, $candidate)
{
if (empty($candidate[‘href’])) {
return false;
}
if (!preg_match(‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>#i’, $html, $match)) {
return false;
}
$href = redent_sitewide_speed_get_attr($match[0], ‘href’);
return redent_sitewide_speed_normalize_url($href) === redent_sitewide_speed_normalize_url($candidate[‘href’]);
}
function redent_sitewide_speed_choose_lcp_candidate($html)
{
$is_single_post = redent_sitewide_speed_html_is_single_post($html);
if (!$is_single_post) {
$titlebar = redent_sitewide_speed_extract_titlebar_background($html);
if ($titlebar) {
return array(
‘type’ => ‘background’,
‘href’ => $titlebar,
‘candidate’ => ‘titlebar’,
);
}
}
if ($is_single_post) {
$featured = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($featured) {
$featured[‘candidate’] = ‘single-featured’;
return $featured;
}
}
$archive = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($archive) {
$archive[‘candidate’] = ‘archive-first-card’;
return $archive;
}
$first = redent_sitewide_speed_extract_first_meaningful_img($html);
if ($first) {
$first[‘candidate’] = ‘first-meaningful-img’;
}
return $first;
}
function redent_sitewide_speed_html_is_single_post($html)
{
if (preg_match(‘/
if (preg_match(‘/(?:^|\s)single-post(?:\s|$)/’, $body[2])) {
return true;
}
}
return (bool) preg_match(‘/
}
function redent_sitewide_speed_extract_titlebar_background($html)
{
if (stripos($html, ‘tm-titlebar-wrapper’) === false) {
return ”;
}
$urls = array();
if (preg_match_all(‘/\.tm-titlebar-wrapper[^{]*\{[^}]*\}/i’, $html, $rules)) {
foreach ($rules[0] as $rule) {
if (preg_match_all(‘/url\(([“\’]?)([^)”\’]+\.(?:webp|jpe?g|png|avif))(?:\1)\)/i’, $rule, $matches)) {
foreach ($matches[2] as $url) {
$urls[] = redent_sitewide_speed_normalize_url($url);
}
}
}
}
$urls = array_values(array_filter(array_unique($urls)));
if (!$urls) {
return ”;
}
foreach (array_reverse($urls) as $url) {
if (preg_match(‘/\.webp(?:\?|$)/i’, $url)) {
return $url;
}
}
return end($urls);
}
function redent_sitewide_speed_extract_first_img($html, $pattern)
{
if (!preg_match($pattern, $html, $match)) {
return null;
}
$tag = $match[0];
if (preg_match(‘/]*>$/is’, $tag, $img_match)) {
return redent_sitewide_speed_img_candidate_from_tag($img_match[0]);
}
return null;
}
function redent_sitewide_speed_extract_first_meaningful_img($html)
{
if (!preg_match_all(‘/]*>/i’, $html, $matches)) {
return null;
}
foreach ($matches[0] as $tag) {
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if (preg_match(‘/(?:logo|avatar|icon|emoji|favicon)/i’, $class)) {
continue;
}
$src = redent_sitewide_speed_img_src($tag);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
continue;
}
$width = (int) redent_sitewide_speed_get_attr($tag, ‘width’);
$height = (int) redent_sitewide_speed_get_attr($tag, ‘height’);
if (($width && $width < 180) || ($height && $height < 120)) {
continue;
}return redent_sitewide_speed_img_candidate_from_tag($tag);
}return null;
}function redent_sitewide_speed_img_candidate_from_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src === '') {
return null;
}$srcset = redent_sitewide_speed_get_attr($tag, 'srcset');
if ($srcset === '') {
$srcset = redent_sitewide_speed_get_attr($tag, 'data-srcset');
}$sizes = redent_sitewide_speed_get_attr($tag, 'sizes');
if ($sizes === '') {
$sizes = redent_sitewide_speed_get_attr($tag, 'data-sizes');
}return array(
'type' => ‘img’,
‘href’ => redent_sitewide_speed_normalize_url($src),
‘srcset’ => $srcset,
‘sizes’ => $sizes,
‘tag’ => $tag,
);
}
function redent_sitewide_speed_img_src($tag)
{
$src = redent_sitewide_speed_get_attr($tag, ‘src’);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
$src = redent_sitewide_speed_get_attr($tag, ‘data-src’);
}
return redent_sitewide_speed_normalize_url($src);
}
function redent_sitewide_speed_get_attr($tag, $attr)
{
$attr = preg_quote($attr, ‘/’);
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([“\’])(.*?)\1/is’, $tag, $match)) {
return html_entity_decode(trim($match[2]), ENT_QUOTES);
}
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([^\s>]+)/is’, $tag, $match)) {
return html_entity_decode(trim($match[1], “\”‘”), ENT_QUOTES);
}
return ”;
}
function redent_sitewide_speed_normalize_url($url)
{
$url = trim(html_entity_decode((string) $url, ENT_QUOTES), ” \t\n\r\0\x0B\”‘”);
if ($url === ”) {
return ”;
}
if (strpos($url, ‘//’) === 0) {
return ‘https:’ . $url;
}
if (strpos($url, ‘/’) === 0) {
return home_url($url);
}
return $url;
}
function redent_sitewide_speed_build_preload_link($candidate)
{
$href = redent_sitewide_speed_normalize_url($candidate[‘href’]);
if ($href === ”) {
return ”;
}
$attrs = array(
‘rel’ => ‘preload’,
‘as’ => ‘image’,
‘href’ => esc_url($href),
‘fetchpriority’ => ‘high’,
‘data-redent-lcp-preload’ => ‘1’,
‘data-redent-lcp-candidate’ => isset($candidate[‘candidate’]) ? sanitize_key($candidate[‘candidate’]) : ‘image’,
);
if (!empty($candidate[‘srcset’])) {
$attrs[‘imagesrcset’] = esc_attr($candidate[‘srcset’]);
}
if (!empty($candidate[‘sizes’])) {
$attrs[‘imagesizes’] = esc_attr($candidate[‘sizes’]);
}
$html = ‘ $value) {
$html .= ‘ ‘ . $name . ‘=”‘ . $value . ‘”‘;
}
return $html . ‘ />’;
}
function redent_sitewide_speed_prioritize_img_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src !== ” && redent_sitewide_speed_get_attr($tag, ‘src’) !== $src) {
if (preg_match(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, ‘ src=”‘ . esc_url($src) . ‘”‘, $tag, 1);
} else {
$tag = preg_replace(‘/)/is’, ”, $tag);
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if ($class !== ” && strpos($class, ‘redent-lcp-image’) === false) {
$tag = preg_replace(‘/\sclass\s*=\s*([“\’])(.*?)\1/is’, ‘ class=”$2 redent-lcp-image”‘, $tag, 1);
} elseif ($class === ”) {
$tag = preg_replace(‘/ 0 && $height > 0 && stripos($tag, ‘aspect-ratio’) === false) {
$ratio = $width . ‘ / ‘ . $height;
if (preg_match(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, ‘ style=”$2; aspect-ratio: ‘ . esc_attr($ratio) . ‘; height: auto;”‘, $tag, 1);
} else {
$tag = preg_replace(‘/]*class=([“\’])(?=[^”\’]*\btm-featured-outer-wrapper\b)(?=[^”\’]*\btm-post-featured-outer-wrapper\b)([^”\’]*)\2[^>]*>)(.{0,1200}?
]*\bwp-post-image\b[^>]*>)#is’,
‘redent_sitewide_speed_stabilize_featured_wrapper_match’,
$html
);
}
function redent_sitewide_speed_stabilize_featured_wrapper_match($match)
{
$open = $match[1];
$rest = $match[4];
if (strpos($open, ‘redent-cls-reserved-media’) === false) {
$open = preg_replace(‘/\sclass=([“\’])(.*?)\1/is’, ‘ class=”$2 redent-cls-reserved-media”‘, $open, 1);
}
if (stripos($open, ‘aspect-ratio’) === false && preg_match(‘/]*>/i’, $rest, $img)) {
$width = (int) redent_sitewide_speed_get_attr($img[0], ‘width’);
$height = (int) redent_sitewide_speed_get_attr($img[0], ‘height’);
if ($width > 0 && $height > 0) {
$style = ‘–redent-featured-ratio: ‘ . $width . ‘ / ‘ . $height . ‘; aspect-ratio: ‘ . $width . ‘ / ‘ . $height . ‘;’;
if (preg_match(‘/\sstyle=([“\’])(.*?)\1/is’, $open)) {
$open = preg_replace(‘/\sstyle=([“\’])(.*?)\1/is’, ‘ style=”$2; ‘ . esc_attr($style) . ‘”‘, $open, 1);
} else {
$open = preg_replace(‘/>$/’, ‘ style=”‘ . esc_attr($style) . ‘”>’, $open, 1);
}
}
}
return $open . $rest;
}
function redent_sitewide_speed_replace_once($search, $replace, $subject)
{
$pos = strpos($subject, $search);
if ($pos === false) {
return $subject;
}
return substr_replace($subject, $replace, $pos, strlen($search));
}
add_action(‘wp_enqueue_scripts’, ‘redent_sitewide_speed_control_jquery’, 1000);
function redent_sitewide_speed_control_jquery()
{
if (!redent_sitewide_speed_is_frontend()) {
return;
}
global $wp_scripts;
if (!($wp_scripts instanceof WP_Scripts)) {
return;
}
foreach (array(‘jquery’, ‘jquery-core’, ‘jquery-migrate’) as $handle) {
if (isset($wp_scripts->registered[$handle])) {
$wp_scripts->add_data($handle, ‘group’, 1);
$wp_scripts->add_data($handle, ‘strategy’, ‘defer’);
}
}
}
add_filter(‘script_loader_tag’, ‘redent_sitewide_speed_defer_jquery_family_tag’, 20, 3);
function redent_sitewide_speed_defer_jquery_family_tag($tag, $handle, $src)
{
if (!redent_sitewide_speed_is_frontend()) {
return $tag;
}
if (!redent_sitewide_speed_script_depends_on_jquery($handle)) {
return $tag;
}
if (stripos($tag, ‘ defer’) !== false || stripos($tag, ‘ async’) !== false || stripos($tag, ‘type=”module”‘) !== false) {
return $tag;
}
return preg_replace(‘/\s*#is’,
”,
$html
);
$html = preg_replace(
‘#]*(?:\bid=([“\’])redent-home-inline-css-family-all-lowrisk-v1-marker\1|\bname=([“\’])redent-home-inline-css-family-all-lowrisk-v1\2))[^>]*>\s*#i’,
”,
$html
);
return $html;
}
function redent_sitewide_speed_normalize_titlebar_background_url($html)
{
if (stripos($html, ‘titlebg.jpg’) === false || redent_sitewide_speed_is_real_home_path()) {
return $html;
}
return preg_replace(
‘#https://www\.redentklinik\.com/wp-content/uploads/2021/08/titlebg\.jpg(?!\.webp)#i’,
‘https://www.redentklinik.com/wp-content/uploads/2021/08/titlebg.jpg.webp’,
$html
);
}
function redent_sitewide_speed_remove_previous_lcp_preload($html)
{
return preg_replace(
‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>\s*#i’,
”,
$html
);
}
function redent_sitewide_speed_existing_preload_matches($html, $candidate)
{
if (empty($candidate[‘href’])) {
return false;
}
if (!preg_match(‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>#i’, $html, $match)) {
return false;
}
$href = redent_sitewide_speed_get_attr($match[0], ‘href’);
return redent_sitewide_speed_normalize_url($href) === redent_sitewide_speed_normalize_url($candidate[‘href’]);
}
function redent_sitewide_speed_choose_lcp_candidate($html)
{
$is_single_post = redent_sitewide_speed_html_is_single_post($html);
if (!$is_single_post) {
$titlebar = redent_sitewide_speed_extract_titlebar_background($html);
if ($titlebar) {
return array(
‘type’ => ‘background’,
‘href’ => $titlebar,
‘candidate’ => ‘titlebar’,
);
}
}
if ($is_single_post) {
$featured = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($featured) {
$featured[‘candidate’] = ‘single-featured’;
return $featured;
}
}
$archive = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($archive) {
$archive[‘candidate’] = ‘archive-first-card’;
return $archive;
}
$first = redent_sitewide_speed_extract_first_meaningful_img($html);
if ($first) {
$first[‘candidate’] = ‘first-meaningful-img’;
}
return $first;
}
function redent_sitewide_speed_html_is_single_post($html)
{
if (preg_match(‘/
if (preg_match(‘/(?:^|\s)single-post(?:\s|$)/’, $body[2])) {
return true;
}
}
return (bool) preg_match(‘/
}
function redent_sitewide_speed_extract_titlebar_background($html)
{
if (stripos($html, ‘tm-titlebar-wrapper’) === false) {
return ”;
}
$urls = array();
if (preg_match_all(‘/\.tm-titlebar-wrapper[^{]*\{[^}]*\}/i’, $html, $rules)) {
foreach ($rules[0] as $rule) {
if (preg_match_all(‘/url\(([“\’]?)([^)”\’]+\.(?:webp|jpe?g|png|avif))(?:\1)\)/i’, $rule, $matches)) {
foreach ($matches[2] as $url) {
$urls[] = redent_sitewide_speed_normalize_url($url);
}
}
}
}
$urls = array_values(array_filter(array_unique($urls)));
if (!$urls) {
return ”;
}
foreach (array_reverse($urls) as $url) {
if (preg_match(‘/\.webp(?:\?|$)/i’, $url)) {
return $url;
}
}
return end($urls);
}
function redent_sitewide_speed_extract_first_img($html, $pattern)
{
if (!preg_match($pattern, $html, $match)) {
return null;
}
$tag = $match[0];
if (preg_match(‘/]*>$/is’, $tag, $img_match)) {
return redent_sitewide_speed_img_candidate_from_tag($img_match[0]);
}
return null;
}
function redent_sitewide_speed_extract_first_meaningful_img($html)
{
if (!preg_match_all(‘/]*>/i’, $html, $matches)) {
return null;
}
foreach ($matches[0] as $tag) {
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if (preg_match(‘/(?:logo|avatar|icon|emoji|favicon)/i’, $class)) {
continue;
}
$src = redent_sitewide_speed_img_src($tag);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
continue;
}
$width = (int) redent_sitewide_speed_get_attr($tag, ‘width’);
$height = (int) redent_sitewide_speed_get_attr($tag, ‘height’);
if (($width && $width < 180) || ($height && $height < 120)) {
continue;
}return redent_sitewide_speed_img_candidate_from_tag($tag);
}return null;
}function redent_sitewide_speed_img_candidate_from_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src === '') {
return null;
}$srcset = redent_sitewide_speed_get_attr($tag, 'srcset');
if ($srcset === '') {
$srcset = redent_sitewide_speed_get_attr($tag, 'data-srcset');
}$sizes = redent_sitewide_speed_get_attr($tag, 'sizes');
if ($sizes === '') {
$sizes = redent_sitewide_speed_get_attr($tag, 'data-sizes');
}return array(
'type' => ‘img’,
‘href’ => redent_sitewide_speed_normalize_url($src),
‘srcset’ => $srcset,
‘sizes’ => $sizes,
‘tag’ => $tag,
);
}
function redent_sitewide_speed_img_src($tag)
{
$src = redent_sitewide_speed_get_attr($tag, ‘src’);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
$src = redent_sitewide_speed_get_attr($tag, ‘data-src’);
}
return redent_sitewide_speed_normalize_url($src);
}
function redent_sitewide_speed_get_attr($tag, $attr)
{
$attr = preg_quote($attr, ‘/’);
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([“\’])(.*?)\1/is’, $tag, $match)) {
return html_entity_decode(trim($match[2]), ENT_QUOTES);
}
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([^\s>]+)/is’, $tag, $match)) {
return html_entity_decode(trim($match[1], “\”‘”), ENT_QUOTES);
}
return ”;
}
function redent_sitewide_speed_normalize_url($url)
{
$url = trim(html_entity_decode((string) $url, ENT_QUOTES), ” \t\n\r\0\x0B\”‘”);
if ($url === ”) {
return ”;
}
if (strpos($url, ‘//’) === 0) {
return ‘https:’ . $url;
}
if (strpos($url, ‘/’) === 0) {
return home_url($url);
}
return $url;
}
function redent_sitewide_speed_build_preload_link($candidate)
{
$href = redent_sitewide_speed_normalize_url($candidate[‘href’]);
if ($href === ”) {
return ”;
}
$attrs = array(
‘rel’ => ‘preload’,
‘as’ => ‘image’,
‘href’ => esc_url($href),
‘fetchpriority’ => ‘high’,
‘data-redent-lcp-preload’ => ‘1’,
‘data-redent-lcp-candidate’ => isset($candidate[‘candidate’]) ? sanitize_key($candidate[‘candidate’]) : ‘image’,
);
if (!empty($candidate[‘srcset’])) {
$attrs[‘imagesrcset’] = esc_attr($candidate[‘srcset’]);
}
if (!empty($candidate[‘sizes’])) {
$attrs[‘imagesizes’] = esc_attr($candidate[‘sizes’]);
}
$html = ‘ $value) {
$html .= ‘ ‘ . $name . ‘=”‘ . $value . ‘”‘;
}
return $html . ‘ />’;
}
function redent_sitewide_speed_prioritize_img_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src !== ” && redent_sitewide_speed_get_attr($tag, ‘src’) !== $src) {
if (preg_match(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, ‘ src=”‘ . esc_url($src) . ‘”‘, $tag, 1);
} else {
$tag = preg_replace(‘/)/is’, ”, $tag);
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if ($class !== ” && strpos($class, ‘redent-lcp-image’) === false) {
$tag = preg_replace(‘/\sclass\s*=\s*([“\’])(.*?)\1/is’, ‘ class=”$2 redent-lcp-image”‘, $tag, 1);
} elseif ($class === ”) {
$tag = preg_replace(‘/ 0 && $height > 0 && stripos($tag, ‘aspect-ratio’) === false) {
$ratio = $width . ‘ / ‘ . $height;
if (preg_match(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, ‘ style=”$2; aspect-ratio: ‘ . esc_attr($ratio) . ‘; height: auto;”‘, $tag, 1);
} else {
$tag = preg_replace(‘/]*class=([“\’])(?=[^”\’]*\btm-featured-outer-wrapper\b)(?=[^”\’]*\btm-post-featured-outer-wrapper\b)([^”\’]*)\2[^>]*>)(.{0,1200}?
]*\bwp-post-image\b[^>]*>)#is’,
‘redent_sitewide_speed_stabilize_featured_wrapper_match’,
$html
);
}
function redent_sitewide_speed_stabilize_featured_wrapper_match($match)
{
$open = $match[1];
$rest = $match[4];
if (strpos($open, ‘redent-cls-reserved-media’) === false) {
$open = preg_replace(‘/\sclass=([“\’])(.*?)\1/is’, ‘ class=”$2 redent-cls-reserved-media”‘, $open, 1);
}
if (stripos($open, ‘aspect-ratio’) === false && preg_match(‘/]*>/i’, $rest, $img)) {
$width = (int) redent_sitewide_speed_get_attr($img[0], ‘width’);
$height = (int) redent_sitewide_speed_get_attr($img[0], ‘height’);
if ($width > 0 && $height > 0) {
$style = ‘–redent-featured-ratio: ‘ . $width . ‘ / ‘ . $height . ‘; aspect-ratio: ‘ . $width . ‘ / ‘ . $height . ‘;’;
if (preg_match(‘/\sstyle=([“\’])(.*?)\1/is’, $open)) {
$open = preg_replace(‘/\sstyle=([“\’])(.*?)\1/is’, ‘ style=”$2; ‘ . esc_attr($style) . ‘”‘, $open, 1);
} else {
$open = preg_replace(‘/>$/’, ‘ style=”‘ . esc_attr($style) . ‘”>’, $open, 1);
}
}
}
return $open . $rest;
}
function redent_sitewide_speed_replace_once($search, $replace, $subject)
{
$pos = strpos($subject, $search);
if ($pos === false) {
return $subject;
}
return substr_replace($subject, $replace, $pos, strlen($search));
}
add_action(‘wp_enqueue_scripts’, ‘redent_sitewide_speed_control_jquery’, 1000);
function redent_sitewide_speed_control_jquery()
{
if (!redent_sitewide_speed_is_frontend()) {
return;
}
global $wp_scripts;
if (!($wp_scripts instanceof WP_Scripts)) {
return;
}
foreach (array(‘jquery’, ‘jquery-core’, ‘jquery-migrate’) as $handle) {
if (isset($wp_scripts->registered[$handle])) {
$wp_scripts->add_data($handle, ‘group’, 1);
$wp_scripts->add_data($handle, ‘strategy’, ‘defer’);
}
}
}
add_filter(‘script_loader_tag’, ‘redent_sitewide_speed_defer_jquery_family_tag’, 20, 3);
function redent_sitewide_speed_defer_jquery_family_tag($tag, $handle, $src)
{
if (!redent_sitewide_speed_is_frontend()) {
return $tag;
}
if (!redent_sitewide_speed_script_depends_on_jquery($handle)) {
return $tag;
}
if (stripos($tag, ‘ defer’) !== false || stripos($tag, ‘ async’) !== false || stripos($tag, ‘type=”module”‘) !== false) {
return $tag;
}
return preg_replace(‘/\s*#is’,
”,
$html
);
$html = preg_replace(
‘#]*(?:\bid=([“\’])redent-home-inline-css-family-all-lowrisk-v1-marker\1|\bname=([“\’])redent-home-inline-css-family-all-lowrisk-v1\2))[^>]*>\s*#i’,
”,
$html
);
return $html;
}
function redent_sitewide_speed_normalize_titlebar_background_url($html)
{
if (stripos($html, ‘titlebg.jpg’) === false || redent_sitewide_speed_is_real_home_path()) {
return $html;
}
return preg_replace(
‘#https://www\.redentklinik\.com/wp-content/uploads/2021/08/titlebg\.jpg(?!\.webp)#i’,
‘https://www.redentklinik.com/wp-content/uploads/2021/08/titlebg.jpg.webp’,
$html
);
}
function redent_sitewide_speed_remove_previous_lcp_preload($html)
{
return preg_replace(
‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>\s*#i’,
”,
$html
);
}
function redent_sitewide_speed_existing_preload_matches($html, $candidate)
{
if (empty($candidate[‘href’])) {
return false;
}
if (!preg_match(‘#]*\brel=([“\’])preload\1)(?=[^>]*\bas=([“\’])image\2)(?=[^>]*\bdata-redent-lcp-preload=([“\’])1\3)[^>]*>#i’, $html, $match)) {
return false;
}
$href = redent_sitewide_speed_get_attr($match[0], ‘href’);
return redent_sitewide_speed_normalize_url($href) === redent_sitewide_speed_normalize_url($candidate[‘href’]);
}
function redent_sitewide_speed_choose_lcp_candidate($html)
{
$is_single_post = redent_sitewide_speed_html_is_single_post($html);
if (!$is_single_post) {
$titlebar = redent_sitewide_speed_extract_titlebar_background($html);
if ($titlebar) {
return array(
‘type’ => ‘background’,
‘href’ => $titlebar,
‘candidate’ => ‘titlebar’,
);
}
}
if ($is_single_post) {
$featured = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($featured) {
$featured[‘candidate’] = ‘single-featured’;
return $featured;
}
}
$archive = redent_sitewide_speed_extract_first_img($html, ‘#]*\bwp-post-image\b)[^>]*>#is’);
if ($archive) {
$archive[‘candidate’] = ‘archive-first-card’;
return $archive;
}
$first = redent_sitewide_speed_extract_first_meaningful_img($html);
if ($first) {
$first[‘candidate’] = ‘first-meaningful-img’;
}
return $first;
}
function redent_sitewide_speed_html_is_single_post($html)
{
if (preg_match(‘/
if (preg_match(‘/(?:^|\s)single-post(?:\s|$)/’, $body[2])) {
return true;
}
}
return (bool) preg_match(‘/
}
function redent_sitewide_speed_extract_titlebar_background($html)
{
if (stripos($html, ‘tm-titlebar-wrapper’) === false) {
return ”;
}
$urls = array();
if (preg_match_all(‘/\.tm-titlebar-wrapper[^{]*\{[^}]*\}/i’, $html, $rules)) {
foreach ($rules[0] as $rule) {
if (preg_match_all(‘/url\(([“\’]?)([^)”\’]+\.(?:webp|jpe?g|png|avif))(?:\1)\)/i’, $rule, $matches)) {
foreach ($matches[2] as $url) {
$urls[] = redent_sitewide_speed_normalize_url($url);
}
}
}
}
$urls = array_values(array_filter(array_unique($urls)));
if (!$urls) {
return ”;
}
foreach (array_reverse($urls) as $url) {
if (preg_match(‘/\.webp(?:\?|$)/i’, $url)) {
return $url;
}
}
return end($urls);
}
function redent_sitewide_speed_extract_first_img($html, $pattern)
{
if (!preg_match($pattern, $html, $match)) {
return null;
}
$tag = $match[0];
if (preg_match(‘/]*>$/is’, $tag, $img_match)) {
return redent_sitewide_speed_img_candidate_from_tag($img_match[0]);
}
return null;
}
function redent_sitewide_speed_extract_first_meaningful_img($html)
{
if (!preg_match_all(‘/]*>/i’, $html, $matches)) {
return null;
}
foreach ($matches[0] as $tag) {
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if (preg_match(‘/(?:logo|avatar|icon|emoji|favicon)/i’, $class)) {
continue;
}
$src = redent_sitewide_speed_img_src($tag);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
continue;
}
$width = (int) redent_sitewide_speed_get_attr($tag, ‘width’);
$height = (int) redent_sitewide_speed_get_attr($tag, ‘height’);
if (($width && $width < 180) || ($height && $height < 120)) {
continue;
}return redent_sitewide_speed_img_candidate_from_tag($tag);
}return null;
}function redent_sitewide_speed_img_candidate_from_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src === '') {
return null;
}$srcset = redent_sitewide_speed_get_attr($tag, 'srcset');
if ($srcset === '') {
$srcset = redent_sitewide_speed_get_attr($tag, 'data-srcset');
}$sizes = redent_sitewide_speed_get_attr($tag, 'sizes');
if ($sizes === '') {
$sizes = redent_sitewide_speed_get_attr($tag, 'data-sizes');
}return array(
'type' => ‘img’,
‘href’ => redent_sitewide_speed_normalize_url($src),
‘srcset’ => $srcset,
‘sizes’ => $sizes,
‘tag’ => $tag,
);
}
function redent_sitewide_speed_img_src($tag)
{
$src = redent_sitewide_speed_get_attr($tag, ‘src’);
if ($src === ” || strpos($src, ‘data:image’) === 0) {
$src = redent_sitewide_speed_get_attr($tag, ‘data-src’);
}
return redent_sitewide_speed_normalize_url($src);
}
function redent_sitewide_speed_get_attr($tag, $attr)
{
$attr = preg_quote($attr, ‘/’);
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([“\’])(.*?)\1/is’, $tag, $match)) {
return html_entity_decode(trim($match[2]), ENT_QUOTES);
}
if (preg_match(‘/\s’ . $attr . ‘\s*=\s*([^\s>]+)/is’, $tag, $match)) {
return html_entity_decode(trim($match[1], “\”‘”), ENT_QUOTES);
}
return ”;
}
function redent_sitewide_speed_normalize_url($url)
{
$url = trim(html_entity_decode((string) $url, ENT_QUOTES), ” \t\n\r\0\x0B\”‘”);
if ($url === ”) {
return ”;
}
if (strpos($url, ‘//’) === 0) {
return ‘https:’ . $url;
}
if (strpos($url, ‘/’) === 0) {
return home_url($url);
}
return $url;
}
function redent_sitewide_speed_build_preload_link($candidate)
{
$href = redent_sitewide_speed_normalize_url($candidate[‘href’]);
if ($href === ”) {
return ”;
}
$attrs = array(
‘rel’ => ‘preload’,
‘as’ => ‘image’,
‘href’ => esc_url($href),
‘fetchpriority’ => ‘high’,
‘data-redent-lcp-preload’ => ‘1’,
‘data-redent-lcp-candidate’ => isset($candidate[‘candidate’]) ? sanitize_key($candidate[‘candidate’]) : ‘image’,
);
if (!empty($candidate[‘srcset’])) {
$attrs[‘imagesrcset’] = esc_attr($candidate[‘srcset’]);
}
if (!empty($candidate[‘sizes’])) {
$attrs[‘imagesizes’] = esc_attr($candidate[‘sizes’]);
}
$html = ‘ $value) {
$html .= ‘ ‘ . $name . ‘=”‘ . $value . ‘”‘;
}
return $html . ‘ />’;
}
function redent_sitewide_speed_prioritize_img_tag($tag)
{
$src = redent_sitewide_speed_img_src($tag);
if ($src !== ” && redent_sitewide_speed_get_attr($tag, ‘src’) !== $src) {
if (preg_match(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\ssrc\s*=\s*([“\’])(.*?)\1/is’, ‘ src=”‘ . esc_url($src) . ‘”‘, $tag, 1);
} else {
$tag = preg_replace(‘/)/is’, ”, $tag);
$class = redent_sitewide_speed_get_attr($tag, ‘class’);
if ($class !== ” && strpos($class, ‘redent-lcp-image’) === false) {
$tag = preg_replace(‘/\sclass\s*=\s*([“\’])(.*?)\1/is’, ‘ class=”$2 redent-lcp-image”‘, $tag, 1);
} elseif ($class === ”) {
$tag = preg_replace(‘/ 0 && $height > 0 && stripos($tag, ‘aspect-ratio’) === false) {
$ratio = $width . ‘ / ‘ . $height;
if (preg_match(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, $tag)) {
$tag = preg_replace(‘/\sstyle\s*=\s*([“\’])(.*?)\1/is’, ‘ style=”$2; aspect-ratio: ‘ . esc_attr($ratio) . ‘; height: auto;”‘, $tag, 1);
} else {
$tag = preg_replace(‘/]*class=([“\’])(?=[^”\’]*\btm-featured-outer-wrapper\b)(?=[^”\’]*\btm-post-featured-outer-wrapper\b)([^”\’]*)\2[^>]*>)(.{0,1200}?
]*\bwp-post-image\b[^>]*>)#is’,
‘redent_sitewide_speed_stabilize_featured_wrapper_match’,
$html
);
}
function redent_sitewide_speed_stabilize_featured_wrapper_match($match)
{
$open = $match[1];
$rest = $match[4];
if (strpos($open, ‘redent-cls-reserved-media’) === false) {
$open = preg_replace(‘/\sclass=([“\’])(.*?)\1/is’, ‘ class=”$2 redent-cls-reserved-media”‘, $open, 1);
}
if (stripos($open, ‘aspect-ratio’) === false && preg_match(‘/]*>/i’, $rest, $img)) {
$width = (int) redent_sitewide_speed_get_attr($img[0], ‘width’);
$height = (int) redent_sitewide_speed_get_attr($img[0], ‘height’);
if ($width > 0 && $height > 0) {
$style = ‘–redent-featured-ratio: ‘ . $width . ‘ / ‘ . $height . ‘; aspect-ratio: ‘ . $width . ‘ / ‘ . $height . ‘;’;
if (preg_match(‘/\sstyle=([“\’])(.*?)\1/is’, $open)) {
$open = preg_replace(‘/\sstyle=([“\’])(.*?)\1/is’, ‘ style=”$2; ‘ . esc_attr($style) . ‘”‘, $open, 1);
} else {
$open = preg_replace(‘/>$/’, ‘ style=”‘ . esc_attr($style) . ‘”>’, $open, 1);
}
}
}
return $open . $rest;
}
function redent_sitewide_speed_replace_once($search, $replace, $subject)
{
$pos = strpos($subject, $search);
if ($pos === false) {
return $subject;
}
return substr_replace($subject, $replace, $pos, strlen($search));
}
add_action(‘wp_enqueue_scripts’, ‘redent_sitewide_speed_control_jquery’, 1000);
function redent_sitewide_speed_control_jquery()
{
if (!redent_sitewide_speed_is_frontend()) {
return;
}
global $wp_scripts;
if (!($wp_scripts instanceof WP_Scripts)) {
return;
}
foreach (array(‘jquery’, ‘jquery-core’, ‘jquery-migrate’) as $handle) {
if (isset($wp_scripts->registered[$handle])) {
$wp_scripts->add_data($handle, ‘group’, 1);
$wp_scripts->add_data($handle, ‘strategy’, ‘defer’);
}
}
}
add_filter(‘script_loader_tag’, ‘redent_sitewide_speed_defer_jquery_family_tag’, 20, 3);
function redent_sitewide_speed_defer_jquery_family_tag($tag, $handle, $src)
{
if (!redent_sitewide_speed_is_frontend()) {
return $tag;
}
if (!redent_sitewide_speed_script_depends_on_jquery($handle)) {
return $tag;
}
if (stripos($tag, ‘ defer’) !== false || stripos($tag, ‘ async’) !== false || stripos($tag, ‘type=”module”‘) !== false) {
return $tag;
}
return preg_replace(‘/
