How to prevent WordPress from redirecting single page to prefixed category archive with same name?

I have been trying to solve this problem for hours. I would like to have a page with a simple slug (/blog) and a category term with the same name (/category/blog) exist on my site together at the same time. But the problem I am running into is that my page (/blog) keeps redirecting to the category archive page (/category/blog).

I have tried the following:

  • adjusting my permalinks by clearly specifying my category base
  • using remove_action(‘template_redirect’, ‘redirect_canonical’); to suppress redirects
  • using add_filter( ‘template_redirect’, ‘blog_redirect_filter’, 10, 3 ); to try and target my blog category specifically

I am running out of ideas. How can I stop my site from redirecting an existing page to a category archive when they each have different slugs?

EDIT

I figured it out! Classic wait-until-you-post-publicly-before-figuring-it-out-yourself problem. It was a fun mix of Yoast, custom permalinks, and category bases all conflicting with each other.

My answer:

  • Make sure your category base is specified in Permalinks. Save them.
  • Remove any custom permalink slugs in the category terms.
  • Go to Yoast > Search Appearance > Taxonomies and scroll to the very bottom. Make sure Category URLs is set to Keep.
  • Clear any cache and/or flush_rewrite_rules.
  • Voila it’s fixed.

Go to Source
Author: Beth Mac

How to enable HTML tags in category description without breaking the category page

I’m trying to include hyperlinks as part of the description on a category page.

Since WordPress strips the necessary HTML tags, I’ve added the following PHP code in a plugin, which stops the HTML tags from getting stripped:

add_action('init','disable_kses');

function disable_kses() {
    remove_filter('pre_term_description', 'wp_filter_kses');
    }

This lets me include HTML tags fine, but when I include a hyperlink in the description, it breaks the page in a weird way, with material from the description being reproduced above the header. This includes all the text from the first hyperlink until the end of the description, but the first link itself isn’t reproduced (only the text for it is). In addition, at the very end of the material, the following is appended to the text:

“>

Other than that, in the place where the description should appear (under the title), everything renders properly, including the hyperlinks.

The HTML that I use to include the hyperlinks is standard:

<a href="http://example.org/">example</a>

My question is what should I be doing differently in order to be able to include hyperlinks as part of the category page description?

Go to Source
Author: Thredolsen

Pagination for custom categories template

I’m a newbie with wordpress theme creation. I want to create a custom category.php file, I’ve implemented the loop and it will display the last 8 posts. I have some fake posts to test if all works well, but I’m not able to add a pagination to the category template I have created.

How I can implement the pagination?I’m thinking to use an infinite scrll using the wp rest api but any other solution will be appreciated.
This is the code I’m using now, the previous link and the next are not displayed

<?php get_header(); ?>
<?php $current_cat = get_queried_object(); ?>
<div class="container mt-5 pt-5">
    <div class="row m-0">
        <div class="col-sm-12 col-md-12 col-lg-12 mt-2 mb-2">
            <p class="text-uppercase font-weight-bold mt-2 mb-2 section-title"><?php echo $current_cat->cat_name; ?></p>
        </div>  
<?php if( have_posts() ): while( have_posts() ): the_post(); ?>        
        <div class="col-sm-12 col-md-3 col-lg-3 h-100 mt-2 mb-2">
            <img class="img-fluid w-100 h-100" src="<?php echo the_post_thumbnail_url(); ?>">
            <a class="h5 mt-2 mb-2" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
            <small class="text-muted d-block"><?php echo get_the_date('j F Y' ,$post->ID); ?></small>
        </div>
    <?php echo next_posts_link(); // not working?>
    <?php echo previous_posts_link(); // not working?>
<?php endwhile; endif; ?>    
    </div>
</div>

<?php get_footer(); ?>

Go to Source
Author: wpnewbie

Add 3rd level to Categories lists

I have a 2 level list of categories displaying checkboxes for a filter.

<?php       
$terms = get_categories( array(
  'orderby' => 'meta_value',
  'meta_key' => 'orden', 
 'parent'  => 0,
    'hide_empty' => 0,  
    'exclude' => 1,  
     ) );
echo '<ul>';
        foreach ($terms as $term) {
        $categories = get_categories('child_of='.intval($term->term_id));
        echo '<li class="desplegable"><label class="desp" for="termino_' . $term->slug . '">' . $term->name . '</label>';
        
            echo '<ul class="cat-submenu">';
        foreach ($categories as $category) {
        if ($category->parent==$term->term_id):
        echo '<li class="submenu-item"><input type="checkbox" id="termino_' . $category->slug . '" name="termino_' . $category->slug . '" /><label for="termino_' . $category->slug . '">' .$category->cat_name. '</label></li>';
        
        endif;
    }
    echo '</ul>';
    echo '</li>';
    }
echo '</ul>';
    ?>

Now I need to include a 3rd level but with no result. Any tips?
Thank you in advance

Go to Source
Author: Juárez