[Support request] Modify archive description

Home Forums Support [Support request] Modify archive description

Home Forums Support Modify archive description

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1932447
    Elí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() (and term_description() inside it) instead of the native one get_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() to get_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 call get_the_archive_description() from my own function. Is that correct?

    Thanks.

    #1933287
    Elvin
    Staff
    Customer Support

    Hi 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 calls term_description() inside its function. You can check the source here – https://developer.wordpress.org/reference/functions/get_the_archive_description/#source

    While term_description() is the base function that pulls from the archive description field.
    https://developer.wordpress.org/reference/functions/term_description/#source

    Tom 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' );

    #1933542
    Elías Gómez

    Hello.

    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 one get_the_archive_description(), that applies the filters? He can do the same, as that function is a ‘wrapper’ that includes term_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.

    #1934340
    Tom
    Lead Developer
    Lead Developer

    Hi 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!

    #1935029
    Elías Gómez

    Hi 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 runs term_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!

    #1936097
    Tom
    Lead Developer
    Lead Developer

    Thanks! Appreciate the feedback 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.