Support » Plugin: DK PDF » Exclude the pdf button text from the excerpt function

  • Resolved fciotola

    (@fciotola)


    Exclude the pdf button text from the excerpt function:

    $post_type = ‘post’;

    // Get all the taxonomies for this post type
    $taxonomies = get_object_taxonomies( array( ‘post_type’ => $post_type ) );

    foreach( $taxonomies as $taxonomy ) :

    // Gets every “category” (term) in this taxonomy to get the respective posts
    $terms = get_terms( $taxonomy );

    foreach( $terms as $term ) : ?>

    <h2 class=”entry-title” ><?php echo $term->name; ?></h2>

    <?php
    $args = array(

    ‘post_type’ => $post_type,
    ‘posts_per_page’ => -1, //show all posts
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => $taxonomy,
    ‘field’ => ‘slug’,
    ‘terms’ => $term->slug,
    ‘cat’ => ‘-3’
    )
    )

    );
    $posts = new WP_Query($args);

    if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?>

    <article id=”prodotti”>

    <?php if(has_post_thumbnail()) { ?>
    ” title=”<?php echo get_the_title(); ?>”>
    <?php the_post_thumbnail(‘archive-custom-size’, array( ‘class’ => ‘aligncenter’ )); ?>

    <?php }
    /* no post image so show default */
    else { ?>
    /assets/img/default-img.png” alt=”<?php echo get_the_title(); ?>” title=”<?php echo get_the_title(); ?>” width=”110″ height=”110″ />
    <?php } ?>

    <h3 >” title=”<?php echo get_the_title(); ?>”><?php echo get_the_title(); ?></h3>

    <?php the_excerpt(); ?>

    </article><!– about-box –>

    <?php endwhile; endif; ?>

    <?php endforeach;

    endforeach; ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author dinamiko

    (@dinamiko)

    Hi fciotola,

    How are you adding the PDF button?
    via DK PDF Settings / PDF Button / Post types to apply
    or manually adding [dkpdf-button] shortcode in each post?

    Thanks.

    Thanks for the fast reply, I’m adding the pdf button via DK PDF Settings.

    Plugin Author dinamiko

    (@dinamiko)

    Hi,
    I’m not being able to reproduce the problem, I don’t see the PDF button in the_excerpt, I only see the button if I change the_excerpt for the_content.

    What you can try to do is filter the_excerpt and delete the button, something like this:

    function custom_excerpt_filter( $excerpt ) {
       remove_shortcode('dkpdf-button');
       $excerpt = str_replace( "[dkpdf-button]", "", $excerpt );
       return $excerpt;
    }
    add_filter( 'get_the_excerpt', 'custom_excerpt_filter' );

    more info here: https://codex.wordpress.org/Plugin_API/Filter_Reference/get_the_excerpt

    Thanks.

    • This reply was modified 3 years, 3 months ago by dinamiko.

    Hi,
    you can see the problem here: http://www.sophiahightech.com/sht/attrezzature-di-prova-sui-materiali/

    How you can see in this page the label of the button is in the start of every single excerpt.

    Plugin Author dinamiko

    (@dinamiko)

    Hi fciotola,

    I don’t see the PDF button in the excerpts in your url, so I think you got it 🙂
    I’m going to close this ticket, feel free to reopen it anytime or create a new one.

    Thanks,
    Emili.

    Plugin Author dinamiko

    (@dinamiko)

    Sorry, I see it now 🙂
    what you have to do is add this code to your theme functions.php

    function custom_excerpt_filter( $excerpt ) {
       $excerpt = str_replace( "Download PDF ", "", $excerpt );
       return $excerpt;
    }
    add_filter( 'get_the_excerpt', 'custom_excerpt_filter' );

    try it and tell me if it works.

    Thanks,
    Emili

    Thanks Dinamiko it work like charm.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Exclude the pdf button text from the excerpt function’ is closed to new replies.