Changeset 3384366
- Timestamp:
- 10/25/2025 08:46:31 AM (5 months ago)
- Location:
- pointalize-faq-markup
- Files:
-
- 3 added
- 2 edited
-
tags/1.1 (added)
-
tags/1.1/pointalize-faq-markup.php (added)
-
tags/1.1/readme.txt (added)
-
trunk/pointalize-faq-markup.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pointalize-faq-markup/trunk/pointalize-faq-markup.php
r3380535 r3384366 4 4 * Plugin URI: https://pointalize.com/ 5 5 * Description: Automatically generates FAQPage JSON-LD from <details class="faq-item">…</details> in post/page content (answers output as plain text). 6 * Version: 1. 06 * Version: 1.1 7 7 * Requires at least: 5.0 8 8 * Requires PHP: 7.4 … … 18 18 19 19 /** 20 * Extract Q&A pairs from <details class="faq-item"> blocks within an HTML string.20 * Extract Q&A pairs from <details> blocks within an HTML string. 21 21 * 22 22 * Rules: 23 23 * - Question = text inside <summary> 24 * - Answer = text inside <div class="faq-content"> if present, else first <p>24 * - Answer = text inside first <p> after the <summary>, else remaining text in <details> 25 25 * - All HTML in answers is stripped → plain text only for clean schema. 26 26 * … … 32 32 if ( ! $html || stripos( $html, '<details' ) === false ) return $faqs; 33 33 34 // Match all <details class="faq-item">...</details>35 if ( ! preg_match_all('/<details[^>]* class="[^"]*\\bfaq-item\\b[^"]*"[^>]*>(.*?)<\\/details>/is', $html, $items) ) {34 // Match all <details>...</details> blocks (any <details>, no class required) 35 if ( ! preg_match_all('/<details[^>]*>(.*?)<\/details>/is', $html, $items) ) { 36 36 return $faqs; 37 37 } 38 38 39 39 foreach ( $items[1] as $block ) { 40 // Question from <summary> 41 if ( ! preg_match('/<summary[^>]*>(.*?)<\\/summary>/is', $block, $qm) ) continue; 40 41 // Extract <summary> (question) 42 if ( ! preg_match('/<summary[^>]*>(.*?)<\/summary>/is', $block, $qm) ) continue; 42 43 $q = trim( wp_strip_all_tags( $qm[1] ) ); 43 44 if ( $q === '' ) continue; 44 45 45 // Answer: prefer .faq-content, else first <p> 46 // Remove the <summary> portion so we can inspect the remaining HTML for the answer 47 $after_summary = preg_replace('/<summary[^>]*>.*?<\/summary>/is', '', $block); 48 49 // Answer: first <p> after <summary>, else fallback to remaining text 46 50 $answer_html = ''; 47 if ( preg_match('/<div[^>]*class="[^"]*\\bfaq-content\\b[^"]*"[^>]*>(.*?)<\\/div>/is', $block, $am) ) { 48 $answer_html = trim( $am[1] ); 49 } elseif ( preg_match('/<p[^>]*>(.*?)<\\/p>/is', $block, $pm) ) { 51 if ( preg_match('/<p[^>]*>(.*?)<\/p>/is', $after_summary, $pm) ) { 50 52 $answer_html = trim( $pm[1] ); 53 } else { 54 $answer_html = trim( $after_summary ); 51 55 } 52 56 if ( $answer_html === '' ) continue; 53 57 54 58 // ---- Strip ALL HTML to plain text ---- 55 // Remove shortcodes (e.g., [shortcode]) .59 // Remove shortcodes (e.g., [shortcode]) 56 60 $answer_plain = strip_shortcodes( $answer_html ); 57 // Strip tags, decode entities (so & -> &), normalize whitespace .61 // Strip tags, decode entities (so & -> &), normalize whitespace 58 62 $answer_plain = wp_strip_all_tags( $answer_plain, true ); 59 63 $answer_plain = html_entity_decode( $answer_plain, ENT_QUOTES | ENT_HTML5, 'UTF-8' ); 60 // Collapse multiple spaces/newlines to single spaces .61 $answer_plain = preg_replace( '/\s+/u', ' ', $answer_plain );64 // Collapse multiple spaces/newlines to single spaces 65 $answer_plain = preg_replace('/\s+/u', ' ', $answer_plain ); 62 66 $answer_plain = trim( $answer_plain ); 63 67 -
pointalize-faq-markup/trunk/readme.txt
r3380535 r3384366 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.4 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 15 15 Pointalize FAQ Markup automatically adds valid **FAQPage JSON-LD structured data** to your WordPress posts and pages — helping your content qualify for Google’s rich FAQ results. 16 16 17 Simply add collapsible FAQ sections using standard HTML `<details class="faq-item">` blocks, and the plugin will detect them automatically, generate the required JSON-LD markup, and inject it into your page’s `<head>` — no Gutenberg blocks, shortcodes, or extra settings required.17 Simply add collapsible FAQ sections using standard HTML `<details>` blocks, and the plugin will detect them automatically, generate the required JSON-LD markup, and inject it into your page’s `<head>` — no Gutenberg blocks, shortcodes, or extra settings required. 18 18 19 19 **Main Features:** 20 * Detects all `<details class="faq-item">` blocks automatically 21 * Extracts questions from `<summary>` and answers from `<p>` tag 20 * Detects all `<details>` blocks and extracts questions and answers automatically. 22 21 * Outputs valid FAQPage JSON-LD schema for Google Rich Results 23 22 * Works on posts, pages, and custom post types … … 29 28 = Features = 30 29 31 * Detects all `<details class="faq-item">` blocks automatically 32 * Extracts questions from `<summary>` and answers from `<div class="faq-content">` or first `<p>` tag 33 * Generates valid **FAQPage JSON-LD** markup 30 * Detects all `<details>` blocks and extracts questions and answers automatically. 31 * Outputs valid FAQPage JSON-LD schema for Google Rich Results 34 32 * Works on posts, pages, and custom post types 35 * Outputs plain-text answers (no HTML)36 * Zero dependencies, zero bloat — pure PHP33 * Converts answers to plain text for maximum schema compatibility 34 * No dependencies, no UI, zero bloat — pure PHP simplicity 37 35 38 36 = Example Usage = … … 40 38 Add the following to your WordPress post or page: 41 39 42 <details class="faq-item">40 <details> 43 41 <summary>How do I enable FAQ markup?</summary> 44 42 <p>Simply install and activate the plugin. It automatically detects your FAQ blocks.</p> 45 43 </details> 46 44 47 <details class="faq-item">45 <details> 48 46 <summary>Does it work on pages too?</summary> 49 47 <p>Yes, it supports posts, pages, and custom post types out of the box.</p> … … 56 54 You can install **Pointalize FAQ Markup** in two simple ways: 57 55 58 = Option 1 — Upload the ZIP manually: = 56 = Option 1 — Install directly from WordPress: = 57 1. Go to **Plugins → Add New** 58 2. Search for “Pointalize FAQ Markup” 59 3. Click **Install Now**, then **Activate** 60 61 = Option 2 — Upload the ZIP manually: = 59 62 1. Download the plugin ZIP file (`pointalize-faq-markup.zip`) 60 63 2. In your WordPress dashboard, go to **Plugins → Add New → Upload Plugin** … … 62 65 4. Activate the plugin 63 66 64 = Option 2 — Install directly from WordPress: = 65 1. Go to **Plugins → Add New** 66 2. Search for “Pointalize FAQ Markup” 67 3. Click **Install Now**, then **Activate** 68 69 After activation, the plugin will automatically detect any `<details class="faq-item">` blocks in your content and output the corresponding FAQ schema. 67 After activation, the plugin will automatically detect any `<details>` blocks in your content and output the corresponding FAQ schema. 70 68 71 69 == Frequently Asked Questions == 72 70 73 71 = Do I need to configure anything? = 74 No. The plugin works automatically on any post or page containing `<details class="faq-item">` elements.72 No. The plugin works automatically on any post or page containing `<details>` elements. 75 73 76 74 = Can I use HTML inside my answers? = … … 93 91 = 1.0 = 94 92 * Initial release 93 = 1.1 = 94 * Simplified even more by removing the faq-item class dependency. 95 95 96 96 == Screenshots ==
Note: See TracChangeset
for help on using the changeset viewer.