skip to Main Content

I have a link with a href which i want to redirect me to category i created.

EX: <a href="/page/category/">Button</a>

my category name: osten & my category id: 43

2

Answers


  1. You can use get_term_link
    https://developer.wordpress.org/reference/functions/get_term_link/.
    For that, if you have the ID, then you can pass it to that function.
    Check the documentation for this function and see what argument you can pass it

    Login or Signup to reply.
  2. Maybe this can help? You can pass either name or ID

    <?php
        // Get the ID of a given category
        $category_id = get_cat_ID( 'Category Name' );
    
        // Get the URL of this category
        $category_link = get_category_link( $category_id );
    ?>
    
    <!-- Print a link to this category -->
    <a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search