• Resolved winy

    (@winy)


    I created a custom archive for search results. I use Relevanssi and Toolset Views.

    To make it work with Relevanssi I followed this topic: https://wp-types.com/forums/topic/custom-search-relevanssi/.

    I added some code to functions.php of my theme. This makes highlight search term work.

    
    // highlight keyword with relevanssi
    // https://wp-types.com/forums/topic/custom-search-relevanssi/
    function highlight_keyword_func($atts, $content) {
        $content = do_shortcode($content);
        if(isset($_GET['s'])){
            $content = relevanssi_highlight_terms($content, $_GET['s']);
        }
        return $content;
    }
    add_shortcode( 'highlight-keyword', 'highlight_keyword_func' );
    

    This is how I implemented the shortcode in the Toolset Views WordPress Archive:

    [wpv-layout-start]
        [wpv-items-found]
    <!-- wpv-loop-start -->
        <ul class="wpv-loop js-wpv-loop">
            <wpv-loop>
                <li>
                <h3>[wpv-post-link]</h3>
                <p><em>[wpv-post-date]<br>Filed under: [wpv-conditional if="( '[wpv-post-type]' eq 'post' )"]News[/wpv-conditional][wpv-conditional if="( '[wpv-post-type]' ne 'post' )"][wpv-post-type show="plural"][/wpv-conditional] [wpv-conditional if="( '[wpv-post-type]' eq 'post' )"] - [wpv-post-taxonomy type="category" format="name"][/wpv-conditional]</em>
                 <br />
                [highlight-keyword][wpv-post-excerpt][/highlight-keyword]
                </p>
                </li>
            </wpv-loop>
        </ul>
        <!-- wpv-loop-end -->
        [/wpv-items-found]
    [wpv-layout-end]
    

    You can view the result I have so far here: http://staging.impel.eu/?s=birds

    Problem: the excerpt in the search results is wrapped in <p></p> tags. However, I did not add these to my template in the Views WordPress archive. These tags are generated by the highlight_keyword shortcode. I temporarily removed this shortcode and then the p tags disappeared.

    How can I resolve this? How can I get rid of these tags?

    • This topic was modified 6 years, 5 months ago by winy.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter winy

    (@winy)

    I resolved it already with help of the Toolset support forum.
    There’s an option for the wpv-post-excerpt shortcode that suppress these paragraph tags:[highlight-keyword][wpv-post-excerpt format="noautop"][/highlight-keyword]

Viewing 1 replies (of 1 total)
  • The topic ‘unwanted p tags when adding shortcode in search results archive’ is closed to new replies.