I am trying to replace a word only on post pages. The issue I am running into is that WordPress page content ends up blank even though this code should only run on post pages.
<?php
/**
* Plugin Name: Wordpress plugin test esmond
* Plugin URI: https://esmondmccain.com
* Description: test plugin.
* Version: 1.0
* Author: Esmond Mccain
* Author URI: https://esmondmccain.com
*/
defined('ABSPATH') or die();
function esmond_enqueue_scripts_styles() {
if(is_page()){
//Styles
wp_enqueue_style( 'bootstrap-css', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css');
//Scripts
wp_enqueue_script( 'bootstrap-js', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js', array('jquery'), true);
}
}
add_action('wp_enqueue_scripts','esmond_enqueue_scripts_styles');
add_filter('the_content', 'replace_word');
function replace_word($text) {
if (is_singular( 'post' )){
$text = str_replace('dog', 'cat', $text);
return $text;
}
}