Support » Plugin: wp-Typography » cannot exclude element

  • Resolved berry metal

    (@erikalleman)


    Hi there,

    I am unable to exclude classes.

    Here is my HTML:
    https://i.imgur.com/K5gfOgi.png

    and here are my settings:
    https://i.imgur.com/KS6wiA9.png

    But links are excluded at the HTML elements as well, and that post entry title is a link, so widows shouldn’t be prevented on that link.

    I have cleared the wp-Typography plugin cache, my grid cache, and all my other caches, CDN, etc…

    Am I specifying something wrong in my settings?

Viewing 15 replies - 31 through 45 (of 50 total)
  • Thread Starter berry metal

    (@erikalleman)

    Hi,
    great, thanks, now the noTypo class is added to the title.

    But look what happens:
    https://i.imgur.com/j1HQTn3.png

    My current post title is dewidowed too as a result, and as a single word is hanging in the last row, it’s ugly.

    That’s why I would need to limit dewidowing to a grid, or limit inclusion to wpTypography.

    Thread Starter berry metal

    (@erikalleman)

    Is it possible to exclude classes like this:
    .related_grid_column .noTypo
    ?

    Then I could restrict it to that grid.

    Thread Starter berry metal

    (@erikalleman)

    Oh no it’s not possible because .related_grid_column is in the HTML, not in the_title itself.

    Plugin Author pepe

    (@pputzer)

    You can always tweak the de-widowing parameters. But really, you are better off disabling it completely. What you intend to do is probably possible, but not with your level of PHP/WordPress knowledge.

    Thread Starter berry metal

    (@erikalleman)

    Ok.
    Thanks for the advice.

    Thread Starter berry metal

    (@erikalleman)

    Now everything is okay, almost. the_content is included, the titles in my related posts are excluded, because all titles are excluded – using the global hook that you suggested.

    But now I would need to re-include my titles in my breadcrumbs, because only the related posts titles should be excluded.

    Is there a way to make breadcrumbs an exception for this global hook that you suggested:

    function add_notypo_to_title( $title ) {
    
        return "<span class="noTypo">$title</span>";
    }
    
    add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );

    Something like add the class to the_title except if the_title is in the breadcrumbs.

    That would solve my problem.

    • This reply was modified 3 months, 2 weeks ago by berry metal.
    Thread Starter berry metal

    (@erikalleman)

    But I was told it’s not possible to check where global hooks like this are used.

    Thread Starter berry metal

    (@erikalleman)

    Hi there,

    The global function above is adding the span also in the backend titles:
    Screenshot:
    https://i.imgur.com/SWSEegm.png

    What would be the correct conditional to add to exclude the backend?

    Thanks in advance.

    Plugin Author pepe

    (@pputzer)

    
    if (! is_admin() ) {
        add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );
    }
    
    Thread Starter berry metal

    (@erikalleman)

    This is my code now:

    function add_notypo_to_title( $title ) {
       if (! is_admin() ) {
        return "<span class='noTypo'>$title</span>";
    }
    
    add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );
    }

    – it removes the span from the backend, but also from the frontend.
    PHP checker found no issues:
    https://i.imgur.com/k7VrnSn.png

    Plugin Author pepe

    (@pputzer)

    Well, that’s not what I suggested.

    Thread Starter berry metal

    (@erikalleman)

    Gotcha, corrected it to:

    function add_notypo_to_title( $title ) {
     
        return "<span class='noTypo'>$title</span>";
    }
    
    if (! is_admin() ) {
        add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );
    }

    Thanks!

    Thread Starter berry metal

    (@erikalleman)

    Is there a way to exclude the current post in this filter?

    I tried something like this:

    function add_notypo_to_title( $title ) {
     
        return "<span class='noTypo'>$title</span>";
    }
    
    $current_id = function_exists( 'vcex_get_the_ID' ) ? vcex_get_the_ID() : get_the_ID();
    if $title !== get_the_title( $current_id ) )  {
       
     
    
        add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );
    
    }

    But it results in a critical error.

    I got inspired from this snippet:

    add_shortcode( 'bbpresscomments', function() {
        $output     = '';
        $current_id = function_exists( 'vcex_get_the_ID' ) ? vcex_get_the_ID() : get_the_ID();
        $topics = new WP_Query( array(
            'post_type' => 'topic',
            'posts_per_page' => -1,
            'fields' => 'ids',
        ) );
        if ( $topics->have_posts() ) {
    
            foreach( $topics->posts as $topic ) {
                if ( get_the_title( $topic ) == get_the_title( $current_id ) ) {
                    $output .= do_shortcode( '[bbp-single-topic id="' . intval( $topic ) . '"]' );
                }
            }
        }
        return $output;
    } );

    Vcex is my theme prefix.

    Then I tried something like this to limit adding the class to the title in my related posts (that would be the goal – but they are the same post type as the posts where I do want to widowing):

    function add_notypo_to_title( $title ) {
     
        return "<span class='noTypo'>$title</span>";
    }
    
    $referer = wp_get_referer();
                $post_id = wp_doing_ajax() ? url_to_postid( $referer ) : $post->ID;
                $related = get_post_meta( $post_id, 'related_post_ids', true );
    
               
    if (! is_admin() ) {
         if (  empty( $related ) ) {
     
    
        add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );
    
    }
    }

    But this also didn’t work.

    I have also tried this to exclude the current post:

    function add_notypo_to_title( $title ) {
     
        return "<span class='noTypo'>$title</span>";
    }
    
    global $wp_query;
    $exclude = $wp_query->post->ID;
    
    if( $exclude != get_the_ID() ) {
    
        add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );
    
    }

    But this code will not add the class anywhere.

    • This reply was modified 3 months, 1 week ago by berry metal.
    • This reply was modified 3 months, 1 week ago by berry metal.
    • This reply was modified 3 months, 1 week ago by berry metal.
    • This reply was modified 3 months, 1 week ago by berry metal.
    • This reply was modified 3 months, 1 week ago by berry metal.
    Plugin Author pepe

    (@pputzer)

    Hi @erikalleman, depending on your exact understanding of “the current post”, yes there are ways to achieve that, but this is all going way beyond wp-Typography support questions. Therefore, I’d ask you to direct your questions to the appropriate fora on this site (and perhaps read a few tutorials on WordPress programming concepts beforehand).

    Thread Starter berry metal

    (@erikalleman)

    I will post to the other forums.
    Thanks.

Viewing 15 replies - 31 through 45 (of 50 total)
  • You must be logged in to reply to this topic.