WordPress.org

Ready to get started?Download WordPress

Forums

add_filter for "get_pagenum_link" not applied? Why? (6 posts)

  1. sepp88
    Member
    Posted 1 year ago #

    Hey guys,

    I'm trying to rewrite the pagination and the search permalinks and want to use add_filter on get_pagenum_link.

    add_filter( 'get_pagenum_link', 'wr_search_pagenum_link' );
    
    function wr_search_pagenum_link( $link ) {
    
        print('this should somehow be fired, right?');
    
        if ( !is_search() )
            return $link;
    
        // Attempt to parse the page number from the provided URL
        if ( !preg_match( '#/page/(\d+)#', $link, $matches ) )
            return $link;
    
        // Return a re-formed URL
        return home_url( '/suche/' . urlencode( get_query_var( 's' ) ) . '/seite/' . $matches[0] );
    }

    However this function above has no effect at all. It just doesn't do anything. I added a print() in order to test it but without any success.

    The function is located in my functions.php.

    Any ideas why that's not working?

  2. s_ha_dum
    Member
    Posted 1 year ago #

    Put die; after your print(...). Do you see your string?

  3. sepp88
    Member
    Posted 1 year ago #

    the die() doesn`t get fired either! The filter just doesn't have any effect at all. the function is not fired!

  4. s_ha_dum
    Member
    Posted 1 year ago #

    Where do you expect this to fire? It is only used a couple of times where paging links are concerned. Look in wp-includes/link-template.php. Are you sure you are using the right hook?

  5. sepp88
    Member
    Posted 1 year ago #

    I expect this to fire somewhere where my pagination is. If I click a paginatin link, or if i'm on the archive page somewhere I guess. I actually just want my pagination and search permalinks to have this permalink structure. But it doesn't work.

  6. s_ha_dum
    Member
    Posted 1 year ago #

    If I click a paginatin link, or if i'm on the archive page somewhere I guess.

    Ok. You have to be more aware of where the hooks fire. They don't just work where you want them too.

    Look in wp-includes/link-template.php, as I said before. That hook gets called a couple of times when the paging links are created, not when you click them, and I am not sure what you mean when you talk about your search permalinks and permalink structure. It may just be that the hook isn't meant to do what you want it to do.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.