Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1129578

    Hello,
    I have two categories created for technical purposes. One is for show featured items in a grid on the home page and the another one is for show items in a dynamic slider (layer slider).

    Im trying to hide the terms of the categories, I have achieved it all over the web except in the home slider (layer slider) with next php code:

    add_filter('get_the_terms', 'hide_categories_terms', 300, 255);
    function hide_categories_terms($terms, $post_id, $taxonomy){
    
        // define which category IDs you want to hide
        $excludeIDs = array(300, 255);
    
        // get all the terms 
        $exclude = array();
        foreach ($excludeIDs as $id) {
            $exclude[] = get_term_by('id', $id, 'category');
        }
    
        // filter the categories
        if (!is_admin()) {
            foreach($terms as $key => $term){
                if($term->taxonomy == "category"){
                    foreach ($exclude as $exKey => $exTerm) {
                        if($term->term_id == $exTerm->term_id) unset($terms[$key]);
                    }
                }
            }
        }
    
        return $terms;
    }

    It works fine, but not in layer slider , in this case im trying to hide with JQuery with next code in child’s functions.php:

    //CUSTOM JQUERY
    function add_custom_code(){
    ?>
    
    <script>
    
    $(document).ready(function () {
    $( ".ls-layer a:contains('_')" ).css( "display", "none" );
    $( "#banner-categorias a:contains('_')" ).css( "display", "none" );
    });
    
    </script>
    			
    	
    <?php
    }
    add_action('wp_footer', 'add_custom_code');

    But don’t work. Any solution? How I can hide the terms on the slider?

    The category terms are “_destacado_home” and “slider_home”

    Thanks in advance. Regards!

    • This topic was modified 5 years, 11 months ago by minguela.
    #1129889

    Hey minguela,

    Unfortunately, it would require quite some time and customization of the theme to achieve this, so I am sorry to tell you that this is not covered by our support. However, if it’s really important for you to get this done, you can always hire a freelancer to do the job for you :)

    You can try to hide them with css:

    
    #banner-categorias {
        display: none !important;
    }
    

    Best regards,
    Victoria

    #1129933

    Hi Victoria

    Thanks for your reply, your solution hide all the categories in the banner, and i want to hide only the categories with “_” in the string.

    Do you know why this code dont want to work?

    $(document).ready(function () {
    $( ".ls-layer a:contains('_')" ).css( "display", "none" );
    $( "#banner-categorias a:contains('_')" ).css( "display", "none" );
    });

    on this piece of html generated by layer slider?

    <div style="top: 153px; left: 365.5px; font-size: 18px; margin: 0px; z-index: auto; width: 438px; height: 22px; padding: 0px; border-width: 0px; border-radius: 0px; line-height: 21.0833px; letter-spacing: 0px; filter: none;" class="ls-layer" id="banner-categorias" data-ls-slidein="1" data-ls-slideout="1" data-ls-active=""> 
    <a href="https://coldwell.crescendoworks.com/categoria/destacado-home/">_destacado_home</a>, 
    <a href="https://coldwell.crescendoworks.com/categoria/_header-slider-home/">_slider home</a>,
    <a href="https://coldwell.crescendoworks.com/categoria/marketing-inmobiliario/">Marketing Inmobiliario</a>
    </div>

    Is so strange, what im doing wrong? is placed in funtions.php in a child folder and the code works fine in the simulator https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_sel_contains

    Thanks again.

    #1129942

    Solved!

    Using a plugin for the jquery code and runs fine!

    I dont know why the code dont work in functions, maybe because is in the bottom of the page?…

    Enfold is the best theme, I’m in love with it, but always i miss a box in the backoffice for insert pieces of custom javascript code. No one is perfect ;)

    Thanks again for your support

    #1130016

    Hi minguela,

    Glad you got it working for you! :)

    IN the post before the last, you’re adding the function but not calling it. Maybe that was the issue.

    If you need further assistance please let us know.

    Best regards,
    Victoria

    #1130289

    Thanks again, Victoria

    Ok, but the exact piece of code in funtions.php that not want to works is:

    //CUSTOM JQUERY
    function add_custom_code(){
    ?>
    
    <script>
    
    $(document).ready(function () {
    $( ".ls-layer a:contains('_')" ).css( "display", "none" );
    $( "#banner-categorias a:contains('_')" ).css( "display", "none" );
    });
    
    </script>
    			
    	
    <?php
    }
    add_action('wp_footer', 'add_custom_code');

    FYI

    Regards

    #1130345

    Hi minguela,

    Can you give us temporary admin access to your website in the private content box below, so that we can have a closer look?

    Best regards,
    Victoria

    #1130379

    Hi Victoria,

    Finally i have been able to solve it without plugin, i have called it from wp_head in function, there was the main problem.

    Here is the final code working fine

    //CUSTOM JQUERY
    //QUITAR CATEGORIAS DEL SLIDER
    function add_custom_code(){
    ?>
    <script>
    jQuery(document).ready(function( $ ){
       $( ".banner-categorias a:contains('_')" ).css( "display", "none" );
       $( ".cat-item:contains('_')" ).css( "display", "none" );
      });
    </script>
    <?php
    }
    add_action('wp_head', 'add_custom_code'); 

    Thanks a lot for your support and interest.

    Best regards

    • This reply was modified 5 years, 11 months ago by minguela.
    #1130457

    Hi,

    I’m glad this was resolved. If you need additional help, please let us know here in the forums.

    Best regards,
    Jordan Shannon

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Exclude categorie terms on layer slider’ is closed to new replies.