| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template Functions for ThinkRank SEO |
| 4 |
* |
| 5 |
* Helper functions for themes to display ThinkRank SEO elements |
| 6 |
* |
| 7 |
* @package ThinkRank\Frontend |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
// Prevent direct access |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Display ThinkRank breadcrumbs |
| 18 |
* |
| 19 |
* Usage in theme templates: |
| 20 |
* <?php thinkrank_breadcrumbs(); ?> |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* |
| 24 |
* @param array $args Optional. Arguments to customize breadcrumb display |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
function thinkrank_breadcrumbs($args = []) { |
| 28 |
/** |
| 29 |
* Fires to display ThinkRank breadcrumbs |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
* |
| 33 |
* @param array $args Breadcrumb display arguments |
| 34 |
*/ |
| 35 |
do_action('thinkrank_breadcrumbs', $args); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Get ThinkRank breadcrumbs data without displaying |
| 40 |
* |
| 41 |
* @since 1.0.0 |
| 42 |
* |
| 43 |
* @return array|null Breadcrumb data or null if not available |
| 44 |
*/ |
| 45 |
function thinkrank_get_breadcrumbs() { |
| 46 |
// Check if ThinkRank is loaded |
| 47 |
if (!function_exists('thinkrank')) { |
| 48 |
return null; |
| 49 |
} |
| 50 |
|
| 51 |
$plugin = thinkrank(); |
| 52 |
if (!$plugin) { |
| 53 |
return null; |
| 54 |
} |
| 55 |
|
| 56 |
$seo_manager = $plugin->get_component('frontend_seo'); |
| 57 |
|
| 58 |
if (!$seo_manager || !method_exists($seo_manager, 'get_current_breadcrumbs')) { |
| 59 |
return null; |
| 60 |
} |
| 61 |
|
| 62 |
return $seo_manager->get_current_breadcrumbs(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Check if ThinkRank SEO is handling the current page |
| 67 |
* |
| 68 |
* @since 1.0.0 |
| 69 |
* |
| 70 |
* @return bool True if ThinkRank is handling SEO for current page |
| 71 |
*/ |
| 72 |
function thinkrank_is_seo_active() { |
| 73 |
// Check if ThinkRank is loaded |
| 74 |
if (!function_exists('thinkrank')) { |
| 75 |
return false; |
| 76 |
} |
| 77 |
|
| 78 |
$plugin = thinkrank(); |
| 79 |
if (!$plugin) { |
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
$seo_manager = $plugin->get_component('frontend_seo'); |
| 84 |
|
| 85 |
if (!$seo_manager || !method_exists($seo_manager, 'has_seo_data')) { |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
return $seo_manager->has_seo_data(); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Get current page SEO metadata |
| 94 |
* |
| 95 |
* @since 1.0.0 |
| 96 |
* |
| 97 |
* @return array Current SEO metadata |
| 98 |
*/ |
| 99 |
function thinkrank_get_seo_metadata() { |
| 100 |
// Check if ThinkRank is loaded |
| 101 |
if (!function_exists('thinkrank')) { |
| 102 |
return []; |
| 103 |
} |
| 104 |
|
| 105 |
$plugin = thinkrank(); |
| 106 |
if (!$plugin) { |
| 107 |
return []; |
| 108 |
} |
| 109 |
|
| 110 |
$seo_manager = $plugin->get_component('frontend_seo'); |
| 111 |
|
| 112 |
if (!$seo_manager || !method_exists($seo_manager, 'get_current_metadata')) { |
| 113 |
return []; |
| 114 |
} |
| 115 |
|
| 116 |
return $seo_manager->get_current_metadata(); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Display custom breadcrumb styles |
| 121 |
* |
| 122 |
* @since 1.0.0 |
| 123 |
* |
| 124 |
* @return void |
| 125 |
*/ |
| 126 |
function thinkrank_breadcrumb_styles() { |
| 127 |
?> |
| 128 |
<style> |
| 129 |
.thinkrank-breadcrumbs { |
| 130 |
margin: 1rem 0; |
| 131 |
font-size: 0.9rem; |
| 132 |
} |
| 133 |
|
| 134 |
.thinkrank-breadcrumbs .breadcrumb-prefix { |
| 135 |
font-weight: 600; |
| 136 |
margin-right: 0.5rem; |
| 137 |
} |
| 138 |
|
| 139 |
.thinkrank-breadcrumbs .breadcrumb-list { |
| 140 |
list-style: none; |
| 141 |
margin: 0; |
| 142 |
padding: 0; |
| 143 |
display: flex; |
| 144 |
flex-wrap: wrap; |
| 145 |
align-items: center; |
| 146 |
} |
| 147 |
|
| 148 |
.thinkrank-breadcrumbs .breadcrumb-item { |
| 149 |
margin: 0; |
| 150 |
padding: 0; |
| 151 |
display: flex; |
| 152 |
align-items: center; |
| 153 |
} |
| 154 |
|
| 155 |
.thinkrank-breadcrumbs .breadcrumb-item a { |
| 156 |
color: #0073aa; |
| 157 |
text-decoration: none; |
| 158 |
} |
| 159 |
|
| 160 |
.thinkrank-breadcrumbs .breadcrumb-item a:hover { |
| 161 |
text-decoration: underline; |
| 162 |
} |
| 163 |
|
| 164 |
.thinkrank-breadcrumbs .breadcrumb-item.current span { |
| 165 |
color: #666; |
| 166 |
font-weight: 500; |
| 167 |
} |
| 168 |
|
| 169 |
.thinkrank-breadcrumbs .breadcrumb-separator { |
| 170 |
margin: 0 0.5rem; |
| 171 |
color: #999; |
| 172 |
} |
| 173 |
</style> |
| 174 |
<?php |
| 175 |
} |
| 176 |
|
| 177 |
// Auto-include breadcrumb styles if breadcrumbs are enabled |
| 178 |
add_action('wp_head', function() { |
| 179 |
// Check if ThinkRank is loaded |
| 180 |
if (!function_exists('thinkrank')) { |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
$plugin = thinkrank(); |
| 185 |
if (!$plugin) { |
| 186 |
return; |
| 187 |
} |
| 188 |
|
| 189 |
$seo_manager = $plugin->get_component('frontend_seo'); |
| 190 |
|
| 191 |
if ($seo_manager) { |
| 192 |
// Check if Site Identity Manager exists and breadcrumbs are enabled |
| 193 |
if (class_exists('ThinkRank\\SEO\\Site_Identity_Manager')) { |
| 194 |
$identity_manager = new \ThinkRank\SEO\Site_Identity_Manager(); |
| 195 |
$settings = $identity_manager->get_settings('site'); |
| 196 |
|
| 197 |
if (!empty($settings['breadcrumbs_enabled'])) { |
| 198 |
thinkrank_breadcrumb_styles(); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
}, 100); |
| 203 |
|