0

I'm working on a website based on the BETHEME, it includes muffin content builder and visual composer. Visual composer is how I hvae build the website.

On the homepage I have included a revolution slider in an visual composer text field. I used the shortcode as follows:

[rev_slider alias="Home_page"]

The problem is that when I search anything in the WordPress search, the results display a piece of javascript code for the homepage result (as it was content of the page).

var htmlDiv = document.getElementById("rs-plugin-settings-inline-css"); var htmlDivCss=""; if(htmlDiv) { htmlDiv.innerHTML = htmlDiv.innerHTML + htmlDivCss; }else{ var htmlDiv = document.createElement("div"); htmlDiv.innerHTML = "" + htmlDivCss + ""; document.getElementsByTagName("head")[0].appendChild(htmlDiv.childNodes[0]); […]

After some research i only found out it's used by revolution slider. How do I cause this script to not display in my search results?

random_user_name
  • 25,694
  • 7
  • 76
  • 115

2 Answers2

2

This seems like a bug with Revolution Slider(not really sure) However this is how I went about fixing it. Edit your functions.php and add the following:

add_post_type_support( 'page', 'excerpt' );

This code modifies the default WordPress content type ‘page’ to add support for excerpts.

After you've done this, edit the page that shows the Javascript code in your search results and add content to the 'Excerpt' field for that page and save. Search again and you'll see that the code is no more.

0

One potential solution is to remove shortcodes from your search results.

One method to do this would be to add the below code to your theme's functions.php file.

function remove_shortcodes_from_search( $content ) {
  // Only modify the content if it is the search results page
  if ( is_search() ) {
    $content = strip_shortcodes( $content );
  }

  return $content;
}

// Assign a very low number (-9999) to priority to ensure it runs before shortcodes are expanded
add_filter( 'the_content', 'remove_shortcodes_from_search', -9999 );
random_user_name
  • 25,694
  • 7
  • 76
  • 115
  • Doesn't seem to work for me, it doesn't display the shortcode itself. only some code generated by revolution slider. – Jurjen Folkertsma Nov 14 '16 at 16:02
  • "Doesn't work for me" isn't very helpful. Did the search results change? If not, are you sure the code above is working / running? If SO, how did the search results change? (NOTE: The rev slider code is showing because of the shortcode you added to the page, which is why I'm attempting to remove the shortcode before the rev slider code can be added) – random_user_name Nov 14 '16 at 16:14
  • You are totally right, It doesn't seem to trigger at all. now when checking i found out there is a problem with jquery loading aswell `Uncaught ReferenceError: jQuery is not defined`. I tried debug mode and loading script in footer/body/head but still the same error... – Jurjen Folkertsma Nov 14 '16 at 17:10