)/i',
// function ( $matches ) {
// $before = $matches[1]; // attributes before alt
// $alt = $matches[2]; // alt value
// $after = $matches[3]; // attributes after alt
// $close = $matches[4]; // /> or >
// if ( mb_strlen( $alt ) > 100 ) {
// // Trim at word boundary, max 100 chars
// $trimmed = mb_substr( $alt, 0, 100 );
// $last_space = mb_strrpos( $trimmed, ' ' );
// if ( $last_space !== false ) {
// $trimmed = mb_substr( $trimmed, 0, $last_space );
// }
// $alt = $trimmed;
// }
// return ' ]*>/i', function($matches) use ($default_alt) {
// $img = $matches[0];
// // Agar alt already hai aur empty nahi hai to skip
// if (preg_match('/alt=["\'](.*?)["\']/i', $img, $alt)) {
// if (!empty($alt[1])) {
// return $img;
// }
// }
// // Alt add ya replace
// if (strpos($img, 'alt=') !== false) {
// $img = preg_replace('/alt=["\'].*?["\']/i', 'alt="'.$default_alt.'"', $img);
// } else {
// $img = str_replace(' Previous Page ';
$args['next_text'] = 'Next Page ';
return $args;
}
add_filter('paginate_links_args','rankmath_seo_pagination_text');
function add_attributes_to_external_links($content) {
$site_url = home_url();
$site_host = parse_url($site_url, PHP_URL_HOST);
return preg_replace_callback('/]+href=["\']([^"\']+)["\'][^>]*>/i', function($matches) use ($site_host) {
$link = $matches[0];
$url = $matches[1];
$host = parse_url($url, PHP_URL_HOST);
// Agar external domain hai
if ($host && $host !== $site_host) {
if (strpos($link, 'target=') === false) {
$link = str_replace(' display_name;
// Hide class
echo '';
add_action('wp_body_open', function() use ($author_name) {
echo 'Articles by ' . esc_html($author_name) . ' ';
echo 'Latest posts and updates written by ' . esc_html($author_name) . ' ';
});
}
}
add_filter('rank_math/frontend/description', 'custom_author_meta_description');
function custom_author_meta_description($description) {
if (is_author()) {
$author = get_queried_object();
$author_name = $author->display_name;
$post_count = count_user_posts($author->ID);
$description = $author_name . " has written " . $post_count . " articles on " . get_bloginfo('name') . ". Read the latest crypto news, analysis and updates.";
}
return $description;
}
function bw_seo_heading_optimizer($content){
if( !is_single() && !is_page() ){
return $content;
}
global $post;
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML(''.$content);
$body = $dom->getElementsByTagName('body')->item(0);
/* -------------------------
REMOVE EMPTY H TAGS
--------------------------*/
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//h1|//h2|//h3|//h4|//h5|//h6') as $node) {
if(trim($node->textContent) == ''){
$node->parentNode->removeChild($node);
}
}
/* -------------------------
H1 CHECK
--------------------------*/
$h1s = $dom->getElementsByTagName('h1');
/* -------------------------
H2 CHECK
--------------------------*/
$newContent = '';
foreach ($body->childNodes as $child) {
$newContent .= $dom->saveHTML($child);
}
return $newContent;
}
add_filter('the_content','bw_seo_heading_optimizer',20);
function bw_add_h1_if_missing_page($content){
// Only for Pages
if( !is_page() ){
return $content;
}
global $post;
// Check if H1 already exists
if (stripos($content, '' . get_the_title($post->ID) . ' ';
$content = $h1 . $content;
}
return $content;
}
add_filter('the_content','bw_add_h1_if_missing_page',20);
function bw_fix_category_multiple_h2() {
if (is_category()) {
ob_start(function($html) {
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML('' . $html);
$h2s = $dom->getElementsByTagName('h2');
$count = 0;
for ($i = $h2s->length - 1; $i >= 0; $i--) {
$h2 = $h2s->item($i);
$count++;
if ($count > 1) {
$span = $dom->createElement('span');
while ($h2->firstChild) {
$span->appendChild($h2->firstChild);
}
foreach ($h2->attributes as $attr) {
$span->setAttribute($attr->nodeName, $attr->nodeValue);
}
$span->setAttribute('class','converted-h2-entry-title entry-title title-animation-black-bold');
$h2->parentNode->replaceChild($span,$h2);
}
}
return $dom->saveHTML();
});
}
}
add_action('template_redirect','bw_fix_category_multiple_h2');
function bw_keep_single_h1_post() {
if (is_single()) {
ob_start(function($html){
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML(''.$html);
$h1s = $dom->getElementsByTagName('h1');
$count = 0;
for ($i = $h1s->length - 1; $i >= 0; $i--) {
$h1 = $h1s->item($i);
$count++;
if ($count > 1) {
$span = $dom->createElement('span');
while ($h1->firstChild) {
$span->appendChild($h1->firstChild);
}
foreach ($h1->attributes as $attr) {
$span->setAttribute($attr->nodeName,$attr->nodeValue);
}
$span->setAttribute('class','converted-h1');
$h1->parentNode->replaceChild($span,$h1);
}
}
return $dom->saveHTML();
});
}
}
add_action('template_redirect','bw_keep_single_h1_post');
function bw_replace_empty_hash_links($content){
if( is_single() || is_page() || is_category() ){
$home = home_url('/');
$content = preg_replace('/href=["\']#["\']/', 'href="'.$home.'"', $content);
}
return $content;
}
add_filter('the_content','bw_replace_empty_hash_links',20);
function bw_replace_hash_links_sitewide() {
ob_start(function($html){
$home = home_url('/');
// Replace href="#"
$html = preg_replace('/href=["\']#["\']/', 'href="'.$home.'"', $html);
return $html;
});
}
add_action('template_redirect','bw_replace_hash_links_sitewide');
Mining Pool News & Updates - BitcoinWorld