- This topic has 5 replies, 2 voices, and was last updated 1 year, 1 month ago by
Tom.
-
AuthorPosts
-
March 13, 2020 at 5:48 pm #1194273
George
Is there a filter I could use to replace post title with a custom field in a custom post archive loop and have this custom field also link to the actual post? Also, is there a way to do that for WP Show Posts, as well?
March 14, 2020 at 8:12 am #1194789Tom
Lead DeveloperLead DeveloperHi there,
the_title()
is the WordPress function responsible for displaying the title. It has a filter (the_title
), but for some reason, that filter is applied all over the site (widget titles, menu items etc..). This means it’s impossible to target only the content titles when using the filter, unfortunately.For now, you’d likely need to create a custom page template with your custom title element.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 14, 2020 at 9:18 am #1194852George
Yeah, I could use an element hook to make it available where I want, though, isn’t that right?
Anyway, I managed to display the custom title with a link to the single post in WP Show Posts like this:
add_action( 'wpsp_before_title','wpsp_add_custom_meta' ); function wpsp_add_custom_meta() { $meta = get_post_meta( get_the_ID(), 'custom_title', true ); if ( isset( $meta ) && '' !== $meta ) $permalink = get_permalink( get_the_ID() ); echo '<h4 class="custom-entry-title" itemprop="headline"><a href="' . $permalink . '"' . 'rel="bookmark"> ' . $meta . '</a>' . '</h4>'; }
Then, I used CSS to hide the original title:
.wp-show-posts-entry-title { display: none; }
Is this a correct way of doing this also from an SEO perspective as well?
March 14, 2020 at 4:07 pm #1195039Tom
Lead DeveloperLead DeveloperInstead of hiding it with CSS, you can use the settings to disable the title. That would be much better from an SEO perspective.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentMarch 14, 2020 at 4:36 pm #1195052George
Hiding the title also hides the alternative title. Utilizing the
wpsp_before_header
hook does the job though so I guess, I will use that!Perfect, thanks, Tom!
March 15, 2020 at 8:01 am #1195583Tom
Lead DeveloperLead DeveloperNo problem 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.