How to change wordpress post title?

add_filter(‘the_title’, ‘wordpress_title’); function wordpress_title($title){ //Return new title if called inside loop if ( in_the_loop() ) return ‘New title’; //Else return regular return $title; } Have you tried the in_the_loop() conditional check to return new title only if called inside loop. That means nav menu’s will not get affected.

How I check if the same post slug has not been used before publishing?

The Ajax way (a little bit dirty, but you can easily enhance it) In your functions.php (or in a plugin, or every where else) : function my_ajax_update(){ if (isset($_POST[‘title’])){ global $wpdb; $title = esc_sql($_POST[‘title’]); if(!$title) return; $page = $wpdb->get_results(” SELECT * FROM $wpdb->posts WHERE post_title LIKE ‘$title’ AND post_type=”event” AND post_status=”publish” LIMIT 1 “); if … Read more

What is the proper filter to add html to a post / page title?

the_title is the correct hook. You can confirm that by checking the source. What you are doing is a bit odd, but it makes sense. Clever solution but I don’t think it was expected. The problem you having seems to be with this line: http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/default-widgets.php#L574 <a href=”<?php the_permalink() ?>” title=”<?php echo esc_attr( get_the_title() ? get_the_title() … Read more

Dynamically add titles to post images if they are empty

You can try the following test plugin, that uses the domDocument class, to see how it works on your HTML. It assumes PHP 5.4+ with LibXML 2.7.8+. <?php /** * Plugin Name: Add Missing Image Title Attributes * Description: For posts in the main loop (Assumes PHP 5.4+ with LibXML 2.7.8+) * Plugin URI: http://wordpress.stackexchange.com/a/188560/26350 … Read more

Adding HTML within an image title attribute

First of all i’d recommend you stop using title attribute for html container purpose: Image title (and the element name speaks for itself) should provide additional information and follow the rules of the regular title: it should be relevant, short, catchy, and concise (a title “offers advisory information about the element for which it is … Read more

How to customize search result page title?

Within the wp_get_document_title() function we have: // If it’s a search, use a dynamic search results title. } elseif ( is_search() ) { /* translators: %s: search phrase */ $title[‘title’] = sprintf( __( ‘Search Results for &#8220;%s&#8221;’ ), get_search_query() ); so you could hook into the document_title_parts filter to adjust it to your neds. Example: … Read more

WordPress i18n-friendly preg_replace post title

We can use the protected_title_format and private_title_format filters, available since WordPress version 2.8: add_filter( ‘protected_title_format’, ‘wpse_pure_title’, 10, 2 ); add_filter( ‘private_title_format’, ‘wpse_pure_title’, 10, 2 ); function wpse_pure_title( $format, \WP_Post $post ) { return ‘mycpt’ === get_post_type( $post ) ? ‘%s’ : $format; } to get rid of the “Private:” and “Protected:” parts on the front-end … Read more

How can I hook into the post editor title field in order to change the HTML?

There is no hook to change the HTML of the input (only the enter_title_here filter to change the placeholder text). You could pull this off easily with jQuery, though. Try this in your functionality plugin or theme’s functions.php file: // Add to the new post screen for any post type add_action( ‘admin_footer-post-new.php’, ‘wpse_add_required_attr_to_title_field’ ); // … Read more