Replace word in “the_content” only for index.php

Few possibilities here:

  1. In index.php you find the_content() and replace it with:

    $content = get_the_content( $more_link_text, $strip_teaser );
    $content = apply_filters( 'the_content', $content );
    $content = str_replace( ']]>', ']]>', $content );
    
    $replace = array(
      'autoplay=""' => ''
    );
    
    $text = str_replace(array_keys($replace), $replace, $text);
    echo $text;
    
  2. Did you try putting that bit of code in index.php? Maybe you have it in functions.php so it will always run but putting it index.php might cause it to only apply there

  3. As @honk31 says you could test for which page you’re on inside the function. This might be good if you want this behaviour to apply on other pages later. E.g.

    function replace_ap($text){
      if (is_home()) {
        $replace = array(
            'autoplay=""' => ''
        );
        $text = str_replace(array_keys($replace), $replace, $text);
        return $text;
      } else {
        return $text;
      }
    }
    
    add_filter('the_content', 'replace_ap');