| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
| add_filter('the_content', function($content) {
|
|
|
| if (!is_singular() || get_the_ID() != 323) {
|
| return $content;
|
| }
|
|
|
| if (!function_exists('aioseo')) {
|
| return $content . '<div style="background: #ffebee; padding: 15px; margin: 20px 0; border-left: 4px solid #f44336;"><strong>Error:</strong> AIOSEO plugin is not active.</div>';
|
| }
|
|
|
| $post_id = 323;
|
| $post = get_post($post_id);
|
|
|
| if (!$post) {
|
| return $content . '<div style="background: #ffebee; padding: 15px; margin: 20px 0; border-left: 4px solid #f44336;"><strong>Error:</strong> Post not found.</div>';
|
| }
|
|
|
| $output = '<div style="background: #e3f2fd; padding: 20px; margin: 20px 0; border-left: 4px solid #2196f3; font-family: monospace; font-size: 14px;">';
|
| $output .= '<h3 style="margin-top: 0; color: #1976d2;">AIOSEO Meta Data for Post ID: ' . $post_id . '</h3>';
|
|
|
|
|
| $aioseo_post = AIOSEO\Plugin\Common\Models\Post::getPost($post_id);
|
|
|
|
|
| $meta_keywords = get_post_meta($post_id, '_aioseo_keywords', true);
|
| $meta_keywords_array = [];
|
| if (!empty($meta_keywords) && is_string($meta_keywords)) {
|
| $meta_keywords_array = array_map('trim', explode(',', $meta_keywords));
|
| }
|
|
|
|
|
| $focus_keyphrase = '';
|
| $additional_keyphrases = [];
|
| if (!empty($aioseo_post->keyphrases) && is_object($aioseo_post->keyphrases)) {
|
| $keyphrases = json_decode(wp_json_encode($aioseo_post->keyphrases), true);
|
| if (!empty($keyphrases['focus']['keyphrase'])) {
|
| $focus_keyphrase = trim($keyphrases['focus']['keyphrase']);
|
| }
|
| if (!empty($keyphrases['additional']) && is_array($keyphrases['additional'])) {
|
| foreach ($keyphrases['additional'] as $additional) {
|
| if (!empty($additional['keyphrase'])) {
|
| $additional_keyphrases[] = trim($additional['keyphrase']);
|
| }
|
| }
|
| }
|
| }
|
|
|
|
|
| $aioseo_title = aioseo()->meta->title->getPostTitle($post);
|
| $aioseo_description = aioseo()->meta->description->getPostDescription($post);
|
|
|
|
|
| $output .= '<strong>Meta Title:</strong> ' . esc_html($aioseo_title) . '<br>';
|
| $output .= '<strong>Meta Description:</strong> ' . esc_html($aioseo_description) . '<br>';
|
| $output .= '<strong>Meta Keywords:</strong> ' . (!empty($meta_keywords_array) ? esc_html(implode(', ', $meta_keywords_array)) : 'Not set') . '<br>';
|
| $output .= '<strong>Focus Keyword:</strong> ' . ($focus_keyphrase ? esc_html($focus_keyphrase) : 'Not set') . '<br>';
|
| $output .= '<strong>Additional Keywords:</strong> ' . (!empty($additional_keyphrases) ? esc_html(implode(', ', $additional_keyphrases)) : 'None') . '<br>';
|
|
|
| $output .= '</div>';
|
|
|
| return $output . $content;
|
| }, 5);
|
| |
| |
Comments