- This topic has 9 replies, 2 voices, and was last updated 8 years, 1 month ago by
Tom.
-
AuthorPosts
-
February 2, 2018 at 9:17 am #486544
Roman
Hi there
On category and post pages in heading h1 shows category name or post title.
I have two questions:1. For categorys. How to remove this heading entirely (with h1 tag)?
2. For both. How to replace h1 tag contents by my custom field from ACF?February 2, 2018 at 9:31 pm #486910Tom
Lead DeveloperLead DeveloperHi there,
Not too sure what you mean by post pages? Single posts?
For the categories, you can do this:
add_filter( 'get_the_archive_title', 'tu_custom_archive_title' ); function tu_custom_archive_title( $title ) { if ( is_category() ) { // Your custom ACF field here } return $title; }February 4, 2018 at 12:17 pm #487931Roman
Yep, single posts.
This code doesn’t work, but thanks for directing me to the right way 🙂
Here is the code for categories (replaces title with advanced custom field):
add_filter( 'single_cat_title', 'tu_custom_archive_title' ); function tu_custom_archive_title( $title ) { $term = get_queried_object(); $mycattitle = get_field('acf_category_title', $term); if ( $mycattitle != '' ) { return $mycattitle; } else { return $title; } }Can you help me do the same for single posts?
February 4, 2018 at 8:32 pm #488086Tom
Lead DeveloperLead DeveloperFor single posts, I believe you would use
the_titlefilter.Let me know if that does it or not 🙂
February 7, 2018 at 2:49 pm #490842Roman
Emmm. It works, but it also replaces text of almost all links with my custom field 🙂 Navigation, sidebar, prev and next post links – all have my title instead link text.
I tried to move the code from snippet to hook (before content). Now navigation is fine, but all that after this hook has changed.
Here is the code:
add_filter( 'the_title', 'tu_custom_post_title' ); function tu_custom_post_title( $title ) { $term = get_queried_object(); $myposttitle = get_field('acf_post_title', $term); if ( $myposttitle != '' ) { return $myposttitle; } else { return $title; } }February 7, 2018 at 8:07 pm #490971Tom
Lead DeveloperLead DeveloperHi there,
Try this instead:
add_filter( 'the_title', 'tu_custom_post_title' ); function tu_custom_post_title( $title ) { $term = get_queried_object(); $myposttitle = get_field('acf_post_title', $term); if ( $myposttitle != '' && in_the_loop() ) { return $myposttitle; } else { return $title; } }February 9, 2018 at 12:30 pm #492485Roman
Better, near perfect ) But prev and next links still have my title. Because they have %title too, I think.
February 9, 2018 at 9:10 pm #492689Tom
Lead DeveloperLead DeveloperI wonder if adding this would fix it:
add_action( 'generate_after_entry_header', 'tu_remove_title_filter' ); function tu_remove_title_filter() { remove_filter( 'the_title', 'tu_custom_post_title' ); }Bit of a long shot.. Let me know 🙂
February 13, 2018 at 10:00 am #495472Roman
Now everything is perfect ) Thanks!
February 13, 2018 at 8:19 pm #495805Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.