Prevent WordPress from adding image’ title automatically

You can try the following to clear the image attachment’s title when it’s inserted but not updated: /** * Empty the image attachment’s title only when inserted not updated */ add_filter( ‘wp_insert_attachment_data’, function( $data, $postarr ) { if( empty( $postarr[‘ID’] ) && isset( $postarr[‘post_mime_type’] ) && wp_match_mime_types( ‘image’, $postarr[‘post_mime_type’] ) ) $data[‘post_title’] = ”; return … Read more

Is there any way to dynamically alter widget titles?

You can use the widget_display_callback (fired, predictably, just prior to displaying a widget 🙂 ). add_filter(‘widget_display_callback’,’wptuts54095_widget_custom_title’,10,3); function wptuts54095_widget_custom_title($instance, $widget, $args){ if ( is_single() ){ //On a single post. $title = get_the_title(); $instance[‘title’] = $instance[‘title’].’ ‘.$title; } return $instance; } The $widget argument is an object of your widget class, and so $widget->id_base will contain the … Read more

Change the_title() of a page dynamically

I would use the is_page_template() conditional: if ( is_page_template( ‘page-courses.php’ ) ) { // The current page uses your // custom page template; // do something } Edit You would use this conditional inside your filter callback: function wpse83525_filter_the_title( $title ) { if ( is_page_template( ‘page-courses.php’ ) ) { return ‘Custom Title’; } return $title; … Read more

How to get current-menu-item title as variable?

This is possible by filtering wp_nav_menu_objects, which is the easiest place to check which item is the current menu item, because WordPress already added the classes for you. add_filter( ‘wp_nav_menu_objects’, ‘wpse16243_wp_nav_menu_objects’ ); function wpse16243_wp_nav_menu_objects( $sorted_menu_items ) { foreach ( $sorted_menu_items as $menu_item ) { if ( $menu_item->current ) { $GLOBALS[‘wpse16243_title’] = $menu_item->title; break; } } … Read more

Apply the_title() filter in post & page title, but not in menu title

Problem Description: Let me rephrase the question first. You want to: Set new title to all post and page type from a meta field. You want this to happen everywhere (home page, single page, widgets etc.) However, you don’t want this title change to happen if the title is on the Navigation Menu. Solution: Before … Read more

Change page title in admin area

add_filter(‘admin_title’, ‘my_admin_title’, 10, 2); function my_admin_title($admin_title, $title) { return get_bloginfo(‘name’).’ • ‘.$title; } You could also do a str_replace on $admin_title to remove “— WordPress” and change “‹”. Look at the top of the wp-admin/admin-header.php file to see what is going on by default.

How to change the case of all post titles to “Title Case”

Updating the posts $all_posts = get_posts( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’ ); foreach ( $all_posts as $single ) { wp_update_post( array( ‘ID’ => $single->ID, ‘post_title’ => to_title_case( $single->post_title ) // see function below )); } Converting a string to “Title Case” And, while not pertinent to WP, for the sake of completeness: function to_title_case( … Read more