Home > Net >  How to change displaying wordpress post title
How to change displaying wordpress post title

Time:03-18

i need a trick about wordpress. i want replace a word from my displaying post title at whole website.(not permantly or not on database. only show temporary at browser.) for example: i want change post word to text here is list my post titles:

1- This is first post title
2- This is second post title
3- This is third post title
4- This is fourth post title

here is my new post title list:

1- This is first text title
2- This is second text title
3- This is third text title
4- This is fourth text title

How can i do this?

CodePudding user response:

in your functions.php:

function title_changer($title) {
    global $post;
    $title = str_replace('text','post',$post->post_title);  
    return $title;
}
add_action('the_title','title_changer');

go to your single.php in your theme path

find get_the_title or the_title, for each one you may change the title_changer function with the specific functions used in the single.php

CodePudding user response:

you can do using Jquery, but you've to change few things as according to your HTML tags h2.entry-title HERE you've to change your post title CSS class and I'm hoping there is an anchor tag inside heading, so I'm replacing the HTML of anchor tag, Please change accordingly and add in your functions.php file.

add_action( 'wp_footer', 'replace_title' );

function replace_title() { ?>

    <script>
    (function($) {

    jQuery('h2.entry-title').each(function(index, value) {

    let text = jQuery(this).find("a").html();
    let result = text.replace("post", "W3Schools");
    jQuery(this).find("a").html(result);
});

    })(jQuery);
    </script>

<?php
}
  • Related