Skip to main contentSkip to footer

I need to add some custom shortcodes to the list of the “removed” ones (so they don’t show in plain text in the results).

However, some of them are built like [shortcode_name text="Need to keep this in results"] and I would like the content in the text parameter to stay in the results.

How do I go about this?

– Duke at Remove shortcode but keep content in X parameter

You can’t do this using the Relevanssi shortcode removal because that’s a binary operation: the whole shortcode is kept or removed, and there’s no way to keep only part of the shortcode.

However, you can do this with the relevanssi_post_content filter hook by removing the shortcode while keeping the attribute text. To get the same effect in excerpts, you can add the same filter function to the relevanssi_pre_excerpt_content filter hook.

add_filter( 'relevanssi_pre_excerpt_content', 'rlv_shortcode_attribute', 8 );
add_filter( 'relevanssi_post_content', 'rlv_shortcode_attribute', 8 );

/**
 * Indexes only the "text" attribute from the 

This is custom heading element

shortcode * * @param string $content Post content * * @return string Post content with the shortcode replaced with just the "text" attribute content. */ function rlv_shortcode_attribute( $content ) { return preg_replace( '/\

This is custom heading element

/im', '\1', $content ); }

Since this particular case was about a Visual Composer shortcode, it’s worth noticing the new filter must happen on priority 8 or earlier, because on priority 9, Relevanssi runs the relevanssi_remove_page_builder_shortcodes() function that removes all Visual Composer shortcodes, including this vc_custom_heading. As long as the new filter runs before the default function, there’s no problem.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Indexing embedded PDFs for the parent post

…) { $block[‘innerContent’] = array( get_post_meta( $block[‘attrs’][‘pdfID’], ‘_relevanssi_pdf_content’, true ) ); } return $block; } Wonderplugin PDF Embed Wonderplugin PDF Embed uses a similar method; the URL of the attachment is in the attribute src. add_filter( ‘relevanssi_content_to_index’, ‘rlv_wonderpdf_content’, 10, 2 ); function rlv_wonderpdf_content( $content, $post ) { $m = preg_match_all(……WordPress. Thus, Relevanssi won’t know the PDF is embedded in the post and cannot index the PDF contents for the parent post. Most of these plugins use shortcodes to embed the PDF viewer on a page. To get Relevanssi to index the embedded PDF contents for the parent post, you……need to establish a connection between the PDF and the post, based on the URL in the shortcode. The same code works with different PDF embedders; you only have to adjust the regex to match the shortcode used by the plugin. WordPress Core File block If you use the default…

WooCommerce: Hidden products in search

Relevanssi by default shows out-of-stock and excluded from catalogue WooCommerce products in the search results, but hides those set to excluded from search (before 2.2.2 and 4.1.2 the default behaviour was to show all products). It is quite easy to make Relevanssi not display hidden products in the results. The…products from the search. This method leads to much faster indexing times. Add this to your site: add_filter( ‘relevanssi_woocommerce_indexing’, ‘rlv_woocommerce_filter’ ); function rlv_woocommerce_filter( $blocks ) { $blocks[‘outofstock’] = true; $blocks[‘exclude-from-catalog’] = true; $blocks[‘exclude-from-search’] = true; return $blocks; } There’s one key for each product visibility level, set the ones you……), ‘product_visibility’, $post_id ) ) { $block = true; } return $block; } This code will unindex products that are set to be excluded from the catalogue, excluded from search or that are out of stock. If you want to keep out of stock items in the search results, just…

Adding direct links to outside pages to search results

…singular name’, ‘textdomain’ ), ‘menu_name’ => _x( ‘Affiliate links’, ‘Admin Menu text‘, ‘textdomain’ ), ‘name_admin_bar’ => _x( ‘Affiliate link’, ‘Add New on Toolbar’, ‘textdomain’ ), ‘add_new’ => __( ‘Add New’, ‘textdomain’ ), ‘add_new_item’ => __( ‘Add New Affiliate link’, ‘textdomain’ ), ‘new_item’ => __( ‘New Affiliate link’, ‘textdomain’ ), ‘edit_item’……=> __( ‘Edit Affiliate link’, ‘textdomain’ ), ‘view_item’ => __( ‘View Affiliate link’, ‘textdomain’ ), ‘all_items’ => __( ‘All Affiliate links’, ‘textdomain’ ), ‘search_items’ => __( ‘Search Affiliate links’, ‘textdomain’ ), ‘parent_item_colon’ => __( ‘Parent Affiliate links:’, ‘textdomain’ ), ‘not_found’ => __( ‘No Affiliate links found.’, ‘textdomain’ ), ‘not_found_in_trash’ =>……__( ‘No Affiliate links found in Trash.’, ‘textdomain’ ), ‘archives’ => _x( ‘Affiliate link archives’, ‘The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4’, ‘textdomain’ ), ‘filter_items_list’ => _x( ‘Filter Affiliate links list’, ‘Screen reader text for the filter links heading on the post…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed