Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1479574

    Hi,
    i added this code to function.php:

    function add_dynamic_hidden_h1() {
        if (!is_admin()) { 
            $page_title = get_the_title(); 
            if (empty($page_title)) {
                $page_title = "Unbekannte Seite"; // Fallback
            }
    
            echo '<div style="position:absolute; left:-9999px; top:-9999px;"> 
                    <h1>My Website - ' . esc_html($page_title) . '</h1>
                  </div>';
        }
    }
    add_action('wp_body_open', 'add_dynamic_hidden_h1');

    As my layout has very less text, because of design reasons, i’m trying to add “My Website -” as h1 (almost for seo reasons) and to load the page-title next to it.

    In my source code it looks like this:

    <div style="position:absolute; left:-9999px; top:-9999px;"> 
                    <h1>My Website - Explore</h1>
                  </div>
    	<div id='wrap_all'>

    Which is what i’m trying to archive.

    Unfortunetly, when i go to Google webmaster tools and do a live test, i get something different:

    <div style="position:absolute; left:-9999px; top:-9999px;" aria-hidden="true"> 
                    <h1>My Website - Explore</h1>
                  </div>
    	<div id="wrap_all" aria-hidden="true">

    Which seems not to works for seo?
    How can i fix that?

    kind regards
    Jak

    #1479929

    Hey Jak73,
    I don’t find this element on your page, perhaps a screenshot would help.

    Best regards,
    Mike

    #1480032

    Got it!
    Thank you

    #1480107

    but you do not want to combine those things mentioned on the other post?

    see f.e.: https://enfold.webers-webdesign.de/impressum/
    see text logo above , when you switch to other posts/pages

    function use_text_logo_only($logo){
        $link = apply_filters( 'avf_logo_link', home_url( '/' ) );
        $logo_tag = "h1";
        $logo_heading = "Webers Webdesign";
        $alt = get_bloginfo( 'name' );    
        $title = get_bloginfo( 'name' );
        $page_title = get_the_title();
    
    if(is_search()){
    	$logo = '<a class="logo text-logo" href="'.$link.'" alt="'.$alt.'" title="'.$title.'"><'.$logo_tag.'>'  .$logo_heading.' - Suchergebnisse</'.$logo_tag.'></a>';
    }
    elseif(is_front_page()){
    	$logo = '<a class="logo text-logo" href="'.$link.'" alt="'.$alt.'" title="'.$title.'"><'.$logo_tag.'>'  .$logo_heading.'</'.$logo_tag.'></a>';
    }
    else{
    	$logo = '<a class="logo text-logo" href="'.$link.'" alt="'.$alt.'" title="'.$title.'"><'.$logo_tag.'>'  .$logo_heading.' - '.$page_title.'</'.$logo_tag.'></a>';
    }
    return $logo;
    }
    add_filter('avf_logo_final_output','use_text_logo_only');
    #top .logo.text-logo  {
      display: flex;
      justify-content: left;
      align-items: center;
      width: auto;
    }
    
    #top .logo.text-logo h1  {
      margin: 0 !important;
      font-size: 30px;
    }
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.