Variables in post title

Just use the the_title filter to hook into the title content and work with that. add_filter( ‘the_title’, function( $title ) { // Manipulate the $title as you want and then return that. // You can add test conditions such as ‘is_main_query’ // (https://codex.wordpress.org/Function_Reference/is_main_query) return $title; } );

Set post title based on first h2 element in the content section

If you can handle this in the PHP side, you might be able to pull the h2 tags from the content using regular expression. PHP VERSION Test content $content = “<h2>This is H2 Content</h2><p>This is p content</p>Random Content<h2>This is another H2 section</h2><b><h2>This the third H2 section</h2></b>”; Grab any text inside H2s preg_match_all(‘#<h2>(.*?)</h2>#’, $content, $matches); // … Read more

Add anchor text to php

You can use the_title filter. Just remember to remove it after wp_list_pages() otherwise it will effect everywhere on the site like in menu, main title, search results etc. Example:- add_filter(‘the_title’, ‘my_custom_title’); wp_list_pages(); remove_filter(‘the_title’, ‘my_custom_title’); function my_custom_title($current_title) { if ($current_title == ‘blue’) { $current_title = $current_title . ‘ widget’; } return $current_title; }

How to prevent WordPress from updating the modified time?

The question of how to customize which post data gets updated has been answered elsewhere on StackExchange. Here is a specific example of how to stop the modified date from being updated: function stop_modified_date_update( $new, $old ) { $new[‘post_modified’] = $old[‘post_modified’]; $new[‘post_modified_gmt’] = $old[‘post_modified_gmt’]; return $new; } add_filter( ‘wp_insert_post_data’, ‘stop_modified_date_update’, 10, 2 ); // do … Read more

Uppercase to sentence case for post titles

You can do that with a command in your database: UPDATE `wp_posts` /* Adjust the prefix! */ SET `post_title` = CONCAT( UCASE( /* First letter uppercase */ SUBSTRING( `post_title`, 1, 1 ) ), ”, LCASE( /* The rest in lowercase */ SUBSTRING( `post_title`, 2, LENGTH(`post_title`) ) ) ); If your author has a habit of … Read more

Locating Global Variables

Child themes The WordPress Way of modifying the theme’s page-templates/front-page.php is to create a child theme, then duplicate this file in the child theme and make the modifications there. Your modified template file will be loaded instead of the parent theme’s file. This allows the parent theme to be updated without losing the modifications made … Read more

Get widget Title from widget id

You can get the widget name from the widget id with this: <?php global $wp_registered_widgets; $id = ‘recent-comments-1’; // example if ( isset($wp_registered_widgets[$id][‘name’]) ) { echo $wp_registered_widgets[$id][‘name’]; } ?>

How to sanitize post title with commas

Depending on how you are outputting the title, the answer is different. But there are two possibilities. By Using wp_title(); If your theme is using the wp_title(); function in its header.php file, you can use the wp_title filter. However, this function is being deprecated since 4.4. add_filter( ‘wp_title’, ‘filter_the_title’ ); function filter_the_title( $title ) { … Read more

Can not set custom title on some WordPress setups

This is most likely due to difference in your theme’s support. Some themes render the title by using the wp_title filter, some by using pre_get_document_title. If your theme has this line in its functions.php file: add_theme_support(‘title-tag’); Then you need to use the pre_get_document_title filter, as follows: add_filter(‘pre_get_document_title’, ‘my_title’); function my_title() { return ‘Some title’; } … Read more