- This topic has 5 replies, 3 voices, and was last updated 2 years, 7 months ago by Tom.
-
AuthorPosts
-
September 16, 2021 at 5:23 am #1932447Elías Gómez
Hello! I want to filter the description of a term when it’s shown in its archive page. But as I can see, you use your own function
generate_do_archive_description()
(andterm_description()
inside it) instead of the native oneget_the_archive_description()
.The native one apply the hook filter
get_the_archive_description
, so we can hook in it and modify the description. But as you don’t use the native function or filter, I can’t do that 🙁Why you do this way? You just need to change
term_description()
toget_the_archive_description()
, that in fact uses the first one if the archive is for a term).How can I do this? I can only think on
remove_action
for your function and callget_the_archive_description()
from my own function. Is that correct?Thanks.
September 16, 2021 at 9:12 pm #1933287ElvinStaffCustomer SupportHi there,
Why you do this way? You just need to change term_description() to get_the_archive_description(), that in fact uses the first one if the archive is for a term).
It’s almost the same thing.
get_the_archive_description()
actually callsterm_description()
inside its function. You can check the source here – https://developer.wordpress.org/reference/functions/get_the_archive_description/#sourceWhile
term_description()
is the base function that pulls from the archive description field.
https://developer.wordpress.org/reference/functions/term_description/#sourceTom skipped the default so he can customize the HTML a bit – https://github.com/tomusborne/generatepress/blob/b60b853630da6d9015722da903e53c8064148b0a/inc/structure/archives.php#L94-L117
But yeah, if you really must remove it go with this.
remove_action( 'generate_after_archive_title', 'generate_do_archive_description' );
September 17, 2021 at 4:00 am #1933542Elías GómezHello.
It’s almost the same thing.
Yes, almost. Because it does not apply the filters, that is what I’m poiting.
get_the_archive_description() actually calls term_description() inside its function. You can check the source here – https://developer.wordpress.org/reference/functions/get_the_archive_description/#source
Yes, I explained that.
“change term_description() to get_the_archive_description(), that in fact uses the first one if the archive is for a term)”Tom skipped the default so he can customize the HTML a bit
Yes, but why he uses
term_description()
instead of the general oneget_the_archive_description()
, that applies the filters? He can do the same, as that function is a ‘wrapper’ that includesterm_description()
but also applies the filters.I thought that GeneratePress followed best practices and that’s why I bought GP Premium. Prevent a user to use the WordPress native hooks is not a good practice. And this support reply is neither at the expected level.
September 17, 2021 at 8:46 pm #1934340TomLead DeveloperLead DeveloperHi there,
Looking at this, it’s likely that
term_description()
was used so we could split up the HTML a bit and have more overall control.We’ll take a look to see if we can achieve the same HTML structure using
get_the_archive_description()
, as we would obviously prefer to use it due to the filter.Thanks!
September 18, 2021 at 1:17 pm #1935029Elías GómezHi Tom.
Both functions return a string. Maybe
get_the_archive_description()
is a little less efficient because it checks first if it is an author or post type archive, but then it runsterm_description()
(and finally returns the string BUT filtered).In the
archives.php
file, the HTML structure is generated AFTER getting the description, it’s not related with that.
Thanks!
September 19, 2021 at 7:52 pm #1936097TomLead DeveloperLead DeveloperThanks! Appreciate the feedback 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.