Skip to content

Commit 6b689a8

Browse files
authored
Merge pull request #70 from n49/slider_v1.0.98
added exclusion tags to json schema
2 parents 6005d0e + 17bd967 commit 6b689a8

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

includes/class-feed-shortcode.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ private function extract_jsonld_schema(&$html) {
2626
if (preg_match('/<head[^>]*>.*?<script[^>]*id=["\']jsonldSchema["\'][^>]*type=["\']application\/ld\+json["\'][^>]*>(.*?)<\/script>.*?<\/head>/is', $html, $matches)) {
2727
// Remove JSON-LD schema from head
2828
$html = preg_replace('/<script[^>]*id=["\']jsonldSchema["\'][^>]*type=["\']application\/ld\+json["\'][^>]*>.*?<\/script>/is', '', $html);
29-
return '<script id="jsonldSchema" type="application/ld+json">' . trim($matches[1]) . '</script>';
29+
// Return with Nitropack exclusion attributes to prevent reordering and optimization
30+
return '<script id="jsonldSchema" type="application/ld+json" data-nitro-exclude="all" data-nitro-ignore="true" data-nitro-no-optimize="true" data-nitro-preserve-ws="true">' . trim($matches[1]) . '</script>';
3031
}
3132
return '';
3233
}
@@ -37,6 +38,7 @@ private function extract_jsonld_schema(&$html) {
3738
* Adds Nitropack exclusion attributes to prevent optimization issues
3839
*/
3940
private function extract_head_resources($html) {
41+
$preconnect_links = '';
4042
$font_links = '';
4143
$other_links = '';
4244
$scripts = '';
@@ -48,8 +50,15 @@ private function extract_head_resources($html) {
4850
// Extract all link tags
4951
if (preg_match_all('/<link[^>]*>/i', $head_content, $link_matches)) {
5052
foreach ($link_matches[0] as $link) {
53+
// Prioritize preconnect links for fonts (must come before font links)
54+
if (preg_match('/rel=["\']preconnect["\']/i', $link)) {
55+
if (strpos($link, 'data-nitro-exclude') === false) {
56+
$link = str_replace('>', ' data-nitro-exclude="all" data-nitro-ignore="true">', $link);
57+
}
58+
$preconnect_links .= $link . "\n";
59+
}
5160
// Prioritize font links (Google Fonts, etc.)
52-
if (preg_match('/fonts\.(googleapis|gstatic)/i', $link) || preg_match('/font/i', $link)) {
61+
else if (preg_match('/fonts\.(googleapis|gstatic)/i', $link) || (preg_match('/rel=["\']stylesheet["\']/i', $link) && preg_match('/font/i', $link))) {
5362
// Add Nitropack exclusion attributes to font links to prevent optimization issues
5463
if (strpos($link, 'data-nitro-exclude') === false) {
5564
// Insert data-nitro attributes before closing >
@@ -72,8 +81,8 @@ private function extract_head_resources($html) {
7281
}
7382
}
7483

75-
// Return with font links first
76-
return trim($font_links . $other_links . $scripts);
84+
// Return with preconnect links first, then font links, then other resources
85+
return trim($preconnect_links . $font_links . $other_links . $scripts);
7786
}
7887

7988
/**
@@ -134,9 +143,15 @@ public function init($atts) {
134143
$reviews = $this->remove_head_section($reviews);
135144

136145
// Output in correct order:
137-
// 1. JSON-LD schema first (for Google crawler/SEO)
146+
// 1. JSON-LD schema first (for Google crawler/SEO) - wrapped to prevent Nitropack reordering
138147
if (!empty($jsonld_schema)) {
148+
// Wrap schema in a container with Nitropack exclusion to preserve position
149+
// Script tags are invisible, so this wrapper doesn't affect rendering but prevents reordering
150+
echo '<!-- OPIO JSON-LD SCHEMA START -->';
151+
echo '<div data-nitro-exclude="all" data-nitro-ignore="true" data-nitro-no-optimize="true" data-nitro-preserve-ws="true" data-nitro-preserve-order="true">';
139152
echo $jsonld_schema;
153+
echo '</div>';
154+
echo '<!-- OPIO JSON-LD SCHEMA END -->';
140155
}
141156

142157
// 2. Head resources (links and scripts) - must come before div with "all: initial"

opio.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Widget for OPIO Reviews
44
Plugin URI:
55
Description: Instantly add OPIO Reviews on your website to increase user confidence and SEO.
6-
Version: 1.0.97
6+
Version: 1.0.98
77
Author: Dhiraj Timalsina <dhiraj@n49.com>
88
Text Domain: widget-for-opio-reviews
99
Domain Path: /languages
@@ -22,7 +22,7 @@
2222

2323
require(ABSPATH . 'wp-includes/version.php');
2424

25-
define('OPIO_PLUGIN_VERSION' , '1.0.97');
25+
define('OPIO_PLUGIN_VERSION' , '1.0.98');
2626
define('OPIO_PLUGIN_FILE' , __FILE__);
2727
define('OPIO_PLUGIN_URL' , plugins_url(basename(plugin_dir_path(__FILE__ )), basename(__FILE__)));
2828
define('OPIO_ASSETS_URL' , OPIO_PLUGIN_URL . '/assets/');

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author: Dhiraj Timalsina
33
Tags: Widget for OPIO Reviews, opio, reviews, rating, widget, google business, testimonials
44
Tested up to: 6.4
5-
Stable tag: 1.0.97
5+
Stable tag: 1.0.98
66
License: GPLv2 or later
77
License URI: http://www.gnu.org/licenses/gpl-2.0.html
88

0 commit comments

Comments
 (0)