| @@ -85,8 +85,10 @@ | ||
| 85 | 85 | // add scripts. |
| 86 | 86 | add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] ); |
| 87 | 87 | // preload image. |
| 88 | 88 | add_action( 'wp_head', [ $this, 'preloadImage' ] ); |
| 89 | + // maybe add json schema. | |
| 90 | + add_action( 'wp_head', [ $this, 'displaySchema' ] ); | |
| 89 | 91 | // add meta title and description. |
| 90 | 92 | add_action( 'wp_head', [ $this, 'addSeoMetaData' ] ); |
| 91 | 93 | } |
| 92 | 94 | |
| @@ -117,8 +119,24 @@ | ||
| 117 | 119 | <?php |
| 118 | 120 | } |
| 119 | 121 | |
| 120 | 122 | /** |
| 123 | + * Display the JSON Schema. | |
| 124 | + * | |
| 125 | + * @return void | |
| 126 | + */ | |
| 127 | + public function displaySchema(): void { | |
| 128 | + $schema = $this->model->getJsonSchemaArray() ?? []; | |
| 129 | + | |
| 130 | + if ( empty( $schema ) ) { | |
| 131 | + return; | |
| 132 | + } | |
| 133 | + ?> | |
| 134 | + <script type="application/ld+json"><?php echo wp_json_encode( $schema ); ?></script> | |
| 135 | + <?php | |
| 136 | + } | |
| 137 | + | |
| 138 | + /** | |
| 121 | 139 | * Preload the product image. |
| 122 | 140 | * |
| 123 | 141 | * @return void |
| 124 | 142 | */ |
| @@ -147,9 +165,9 @@ | ||
| 147 | 165 | * @param string $title The title. |
| 148 | 166 | * |
| 149 | 167 | * @return string |
| 150 | 168 | */ |
| 151 | - public function disallowPreTitle( $title ) { | |
| 169 | + public function disallowPreTitle( $title ): string { | |
| 152 | 170 | if ( ! empty( $this->model->id ) ) { |
| 153 | 171 | return ''; |
| 154 | 172 | } |
| 155 | 173 | return $title; |