arie_cristianD

add preferred source

Sep 10th, 2026
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. function jnews_add_preferred_source_after_content( $content ) {
  2.     if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
  3.         return $content;
  4.     }
  5.  
  6.     $domain = wp_parse_url( home_url(), PHP_URL_HOST );
  7.  
  8.     if ( empty( $domain ) ) {
  9.         return $content;
  10.     }
  11.  
  12.     $preferred_source_url = add_query_arg(
  13.         'q',
  14.         $domain,
  15.         'https://www.google.com/preferences/source'
  16.     );
  17.  
  18.     $button = sprintf(
  19.         '<div class="jnews-custom-preferred-source">
  20.            <a href="%1$s" class="jnews-custom-preferred-source-button" target="_blank" rel="noopener noreferrer">
  21.                Add us as a Preferred Source on Google
  22.            </a>
  23.        </div>',
  24.         esc_url( $preferred_source_url )
  25.     );
  26.  
  27.     return $content . $button;
  28. }
  29.  
  30. add_filter( 'the_content', 'jnews_add_preferred_source_after_content', 20 );
Advertisement
Add Comment
Please, Sign In to add comment