- This topic has 8 replies, 2 voices, and was last updated 1 week, 4 days ago by
Elvin.
-
AuthorPosts
-
May 31, 2020 at 9:06 pm #1309330
stephen
Was wondering if there is a way to add the “title” attribute to links on the links on the main page?
For example, we are looking to have the page title for the links on the main page to automatically have the “title=”PAGE-TITLE-HERE attribute. Is there a way to make it automatically display like that on the archived/main page links?
June 1, 2020 at 8:28 am #1309989stephen
Anything on this?
June 1, 2020 at 9:30 am #1310068Tom
Lead DeveloperLead DeveloperHi there,
This is for the post titles? There isn’t a filter for this at the moment.
Wouldn’t the title attribute be identical to the actual title of the post that’s already displaying?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJune 1, 2020 at 9:31 am #1310073stephen
Yes and yes. We are trying to add the “title” attribute to links on the main page/archived pages for SEO.
June 1, 2020 at 3:24 pm #1310399Tom
Lead DeveloperLead DeveloperIn that case, you would likely need to copy the
content.php
from the parent theme and add it to your child theme. Then you could add the title attribute to this line: https://github.com/tomusborne/generatepress/blob/2.4.2/content.php#L34So it would look like this:
the_title( sprint( '<h2 class="entry-title" itemprop="headline"><a href="%1$s" rel="bookmark" title="%2$s>', esc_url( get_permalink() ), the_title_attribute( 'echo=0' ) ), '</a></h2>' );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJune 1, 2020 at 3:33 pm #1310408stephen
I got it to work with a few tweaks to the code above wit hthe following:
the_title( sprintf( '<h2 class="entry-title" itemprop="headline"><a href="%s" rel="bookmark" title="%2$s">', esc_url( get_permalink() ), the_title_attribute( 'echo=0' ) ), '</a></h2>' );
Thank you so much for helping. You guys are the best.
June 2, 2020 at 9:15 am #1311487Tom
Lead DeveloperLead DeveloperGlad I could help 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJanuary 14, 2021 at 12:53 pm #1619048stephen
Hey, we just updated to the latest theme and was wondering how we could achieve this again? The code is slightly different now on the new theme.
January 14, 2021 at 8:45 pm #1619407Elvin Customer Support
Hi,
This should PHP snippet should achieve the same result.
add_filter( 'generate_get_the_title_parameters', function( $params ) { if ( ! is_singular() ) { $params = array( 'before' => sprintf( '<h2 class="entry-title"%2$s><a href="%1$s" rel="bookmark" target="_blank" title="%3$s">', esc_url( get_permalink() ), 'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : '', the_title_attribute( 'echo=0' ) ), 'after' => '</a></h2>', ); } return $params; } );
A wise man once said:
"Have you cleared your cache?" -
AuthorPosts
- You must be logged in to reply to this topic.