\' + \'

\' + \'

\' + \'\' + \'\'; $(this).before(row); }); // Remove FAQ row $(document).on("click", ".remove-faq-row", function(e) { e.preventDefault(); $(this).closest(".faq-row").remove(); }); }); ' ); } /** * Add the main SEO + FAQ meta box. */ public function add_meta_box() { add_meta_box( 'advanced_seo_meta_box', __( 'Advanced SEO & AI FAQ Schema', 'advanced-seo-meta' ), array( $this, 'render_meta_box' ), ['post', 'page'], 'normal', 'default' ); } /** * Render the meta box (Title, Description, FAQ builder). */ public function render_meta_box( $post ) { wp_nonce_field( 'advanced_seo_nonce', 'advanced_seo_nonce' ); // Get saved values $seo_title = get_post_meta( $post->ID, '_seo_title', true ); $seo_description = get_post_meta( $post->ID, '_seo_description', true ); $faq_data = get_post_meta( $post->ID, '_seo_faq', true ); if ( ! is_array( $faq_data ) ) $faq_data = array(); ?>

$questions[ $i ], 'answer' => $answers[ $i ] ); } } update_post_meta( $post_id, '_seo_faq', $faq_pairs ); } /** * Override the tag. */ public function custom_title( $title ) { if ( is_singular() ) { $custom = get_post_meta( get_queried_object_id(), '_seo_title', true ); if ( ! empty( $custom ) ) return $custom; } return $title; } /** * Output Description & Keywords. */ public function output_meta_tags() { if ( ! is_singular() ) return; $id = get_queried_object_id(); if ( $desc = get_post_meta( $id, '_seo_description', true ) ) echo '<meta name="description" content="' . esc_attr( $desc ) . '" />' . "\n"; // (Optional: We leave keywords empty intentionally, but if you insist, uncomment below) // if ( $kw = get_post_meta( $id, '_seo_keywords', true ) ) echo '<meta name="keywords" content="' . esc_attr( $kw ) . '" />' . "\n"; } /** * Output Open Graph (Facebook/LinkedIn). */ public function output_og_tags() { if ( ! is_singular() ) return; $id = get_queried_object_id(); $post = get_post( $id ); $title = get_post_meta( $id, '_seo_title', true ) ?: $post->post_title; $desc = get_post_meta( $id, '_seo_description', true ) ?: wp_trim_words( $post->post_content, 30 ); echo '<meta property="og:title" content="' . esc_attr( $title ) . '" />' . "\n"; echo '<meta property="og:description" content="' . esc_attr( $desc ) . '" />' . "\n"; echo '<meta property="og:url" content="' . esc_url( get_permalink() ) . '" />' . "\n"; echo '<meta property="og:type" content="article" />' . "\n"; } /** * Output JSON-LD FAQ Schema (The secret weapon for AI search). */ public function output_faq_schema() { if ( ! is_singular() ) return; $id = get_queried_object_id(); $faq_data = get_post_meta( $id, '_seo_faq', true ); if ( empty( $faq_data ) || ! is_array( $faq_data ) ) return; $schema = array( '@context' => 'https://schema.org', '@type' => 'FAQPage', 'mainEntity' => array() ); foreach ( $faq_data as $faq ) { $schema['mainEntity'][] = array( '@type' => 'Question', 'name' => $faq['question'], 'acceptedAnswer' => array( '@type' => 'Answer', 'text' => $faq['answer'] ) ); } echo '<script type="application/ld+json">' . json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . '</script>' . "\n"; } } new Advanced_SEO_Meta();