Set page title in WordPress with PHP
Set page title in WordPress with PHP
Set page title in WordPress with PHP
You have already mentioned the function wp_title(). Right before outputting the title, it passes its value through the filter wp_title, which can be used here to prepend with additional information. add_filter(‘wp_title’, ‘WPSE_20181106_prepend_title’, 10, 3); function WPSE_20181106_prepend_title($title, $sep, $seplocation) { // not a single post if (!is_singular(‘post’)) { return $title; } // IDs of categories that … Read more
2 ways to do this. Method 1. Modifies the title output everywhere. In your theme’s functions.php file, put the following code: function cc_month_in_title($title, $id) { $month = get_the_modified_date(‘ F, Y’, $id); $title = $title.$month; return $title; } add_filter(‘the_title’,’cc_month_in_title’, 10, 2); Method 2. Modifies the title output only in the specific template. In this case, open … Read more
How to get page title () in a different order?
long-title posts do not want published
how to get wp_query posts only first letter of alphabet A?
You can do that like this: function add_label_to_post_title( $title=”” ) { global $post; if( ‘post’ == $post->post_type && trim( $title ) != “” ){ $title_words = explode( ” “, $title ); $word_count = count( $title_words ); //Sets how many words should be wrapped $words_to_wrap = 2; $last_word_index = $word_count > $words_to_wrap ? $words_to_wrap – 1 … Read more
Maybe you can add a higher priority to your filter as the 3rd parameter of the hook: /** * Modify the data * * @param String $data * * @return String $data */ function change_title( $data ) { global $post; return ‘Page ID ‘ . $data; } add_filter( ‘the_title’, ‘change_title’, 15 ); The default priority … Read more
You can add a filter in the title like: add_filter(‘the_title’, function ($title) { if (is_single()) { $categories = get_the_category(get_the_ID()); // Assuming the post has many categories will take the first $category = reset($categories); return $category->name .’ – ‘.$title; } return $title; });
Post title not displaying as recorded in the wp_posts table