Tag Info

Hot answers tagged

15

I would do it this way: functions.php <?php add_filter( 'posts_where', 'title_like_posts_where', 10, 2 ); function title_like_posts_where( $where, &$wp_query ) { global $wpdb; if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) { $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( ...


13

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 ...


11

add_filter('admin_title', 'my_admin_title', 10, 2); function my_admin_title($admin_title, $title) { return get_bloginfo('name').' &bull; '.$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.


11

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 ) ...


11

There is no documentation on it but you could always apply a filter to the_title like this: add_filter('the_title','some_callback'); function some_callback($data){ global $post; // where $data would be string(#) "current title" // Example: // (you would want to change $post->ID to however you are getting the book order #, // but you ...


11

The easiest workaround could be: function myplugin_update_slug( $data, $postarr ) { if ( !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { $data['post_name'] = sanitize_title( $data['post_title'] ); } return $data; } add_filter( 'wp_insert_post_data', 'myplugin_update_slug', 99, 2 );


11

I just found the answer and instead of putting this in the Title: <!--:en-->My English Title<!--:--><!--:fr-->My French Title<!--:--> We need to put this code: [:en]My English Title[:fr]My French Title and qTranslate does the rest :)


10

If you have the attachment id, you can use get_the_title() $attachment_title = get_the_title($attach_id) http://codex.wordpress.org/Function_Reference/get_the_title


7

<?php if(count($related)) { echo "<div>Read More<ul>"; foreach($related as $id) { echo '<li><a href="'.get_permalink( $id ).'">'.get_the_title( $id ).'</a></li>';     }     echo "</ul></div>";   } ?>  


7

you can use this function that jumps by google "get post by title" /** * Retrieve a post given its title. * * @uses $wpdb * * @param string $post_title Page title * @param string $post_type post type ('post','page','any custom type') * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. * @return mixed */ function ...


7

I use a code which differs from yours a little bit. There is no need to get the current screen using the enter_title_here-filter because you have already a post-object: /** * Filter: Modifies the standard placeholder text * @param string $title * @param WP_Post $post * @return string */ function my_enter_title_here( $title, $post ) { if ( ...


6

It looks like your site's title is empty. Fill it out or try for example: add_filter( 'wp_title', function( $title ) { return trim( $title ); } ); to remove the blank space in front. For your setup, the following part of wp_title() is responsible for the blank space: $title = $prefix . implode( " $sep ", $title_array ); So when you're on a single ...


6

There are actually two problems: The & is encoded as &amp;, so you have to use html_entity_decode() first. Multi-byte characters need more than one byte, and strlen() will fail with them. Don’t use strlen(). So use something like this: $title = html_entity_decode( get_the_title(), ENT_XML1, 'UTF-8' ); $length = mb_strlen( $title, 'utf-8' );


6

Also, run the slug from sanitize_title_with_dashes() through wp_unique_post_slug() to ensure that it's unique. It will automatically append '-2', '-3' etc. if it's needed.


6

add_filter('widget_title', my_title); function my_title($title) { // Cut the title to 2 parts $title_parts = explode(' ', $title, 2); // Throw first word inside a span $title = '<span class="my_class">'.$title_parts[0].'</span>'; // Add the remaining words if any if(isset($title_parts[1])) $title .= ' ...


6

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(); ...


5

You can use your own hook for widget_title action. You can determine specific widget by $id_base parameter which is passed as third argument to the hook. It should work like this: function myplugin_widget_title( $title, $instance, $id_base ) { if ( !is_single() ) { return $title; } $post_title = get_the_title(); switch ( $id_base ) ...


5

The WPSEO plugin by Yoast has a filter for the title: 'wpseo_title'. You'll need to add something like this: add_filter('wpseo_title', 'filter_product_wpseo_title'); function filter_product_wpseo_title($title) { if( is_singular( 'product') ) { $title = //your code } return $title; }


5

Assuming this question is related to Wordpress, here is answer :- You can update the titles directly into your mySQL database using simple update function. one of my user publishs all his posts uppercase (title) i want to edit them and make it normal. – Using some conditional statements as I mentioned in this code, you can restrict the update for ...


5

Disable all plugins. One of them puts all words with capital letters in a <span class="caps"> container. In <meta property="og:title" content="test <span class="caps">CSS</span> title" /> … this closes the <head> section automatically because output is not allowed in <head>. If you have found the plugin tell its ...


5

You could change the post title when it is viewed: add_action( 'the_post', 'wpse_94856_title_update' ); function wpse_94856_title_update( $post ) { if ( empty ( $post->post_title ) ) return; $new_title = mb_convert_case( $post->post_title, MB_CASE_TITLE, "UTF-8" ); if ( $post->post_title === $new_title ) return; ...


5

In WordPress, "---" and " -- " become em-dashes (— &#8212;) and "--" becomes an en-dash (— #8212;). The sanitize_title_with_dashes() function doesn't catch these. That function uses the databased copy, but the title displayed to the user always goes through a texturize function. So if we replace en/em dashes on their way into the database, ...


5

You can try the following code. function custom_post_type_title ( $post_id ) { global $wpdb; if ( get_post_type( $post_id ) == 'cars' ) { $engine= ', '.get_post_meta($post_id, 'Engine', true).'l'; $terms = wp_get_object_terms($post_id, 'brand'); $abrand= ' '.$terms[0]->name; $amodel = ' '.$terms[1]->name; ...


5

You can globalize $post to work out the post type. Example: add_filter( 'the_title', 'add_the_title_prefix' ); function add_the_title_prefix( $title ) { global $post; if ( 'custom_post_type_name' != $post->post_type ) return $title; return "<span>Press:</span> {$title}"; }


5

Hook into the_post – called when the post is actually used – and fill the title. Be aware the slug has to be changed too. If you are used not to enter a title, hook into save_post too, and let the same code do this for you. The code Download on GitHub <?php /** * Plugin Name: T5 Lazy Title Updates * Description: Fill missing post titles from content ...


5

You can try this: /** * Modify the header title on single pages * but exclude the 'post', 'attachment' and 'page' post types. * * Header Title: Site Name | Post Type Label | Post Title * * Example: My Shopping Site | Products | Sony Playstation 4 */ function wpse_141145_wp_title( $title, $sep ) { if( is_single() && 'post' !== ( ...


5

Custom fields are perfectly suited for this purpose. WP Ref. IF the metabox titled Custom Fields is not visible on your post edit screen, you may need to enable the view with the Screen Options menu at the top right of your editor. For each post, simply create the secondary title and assign it a value. Where you would like this information to display, ...


4

The two title tags can be explained as that you are using a theme that is written for Wordpress4.1 and actually is using 4.1. As from 4.1 you don't need to call wp_title() in the head any more, you can make use of new title_tag theme support tag which automatically adds the wp_title() tag in the header The parent theme you are using are most probably ...


4

Ok my bad found the answer on the codex page but at the very bottom so I'm adding this here as well so if anyone like my didn't catch it on WordPress's codex, they can find it here :) Just use get_admin_page_title(); See the example 1 below: function register_my_custom_submenu_page() { add_submenu_page( 'tools.php', 'My Custom ...


4

There is nothing after the slash. Do not see the address as something like a directory structure. It is just an address, a unique string to tell WordPress which content it should load. That content will be loaded into any template, and that template again could be composed of multiple separate files from the theme.



Only top voted, non community-wiki answers of a minimum length are eligible