24

1. Change post title in post list column I misunderstood what you wanted - obviously. You can do that like this: add_action( 'admin_head-edit.php', 'wpse152971_edit_post_change_title_in_list' ); function wpse152971_edit_post_change_title_in_list() { add_filter( 'the_title', 'wpse152971_construct_new_title', 100, 2 ...


11

The two are not 100% identical, though they are close. the_title() will echo content by default but the third parameter can be used to change that default. the_title() prepends the optional $before and appends the optional $after arguments. If theme or plugin code uses these arguments the output of the two functions will be different. If you take a look at ...


9

A post or page has only one title, the title tag <title> is the document title. The filter wp_title filters the output of wp_title() function, which was used before to output the title of the document. In WordPress 4.1, the title-tag support in themes was introduced and wp_get_document_title() is used instead of wp_title(). So, if your theme supports ...


6

You can make use the queried object to return the title of the page used as blogpage You can use the following: (Require PHP 5.4+) $title = get_queried_object()->post_title; var_dump( $title );


4

The simplest method may be to just save titles as last name / first name, then they will naturally sort. You can then reverse the title when you output it in the template. Your attempt to modify the orderby query var is fundamentally flawed. Order is created by MySQL, which doesn't understand PHP, and can't be modified after the query has happened. If the ...


4

Did you use it like that?? <a href="<?php get_permalink($id); ?>"><?php the_title($id); ?></a> for use to that foreach($ids as $id){ $link = get_permalink($id); $title = get_the_title($id); $links .= '<a href="'.$link.'">'.$title.'</a>'.'<br/>' ; //$links .= $link . ' <br>'; } get_permalink ...


4

First things first, lets clean up your code: <?php $wptitle = the_title(); $wptitle = str_replace('&', 'and', $wptitle);?><?php echo $wptitle; ?> Lets remove the PHP tag spam and put things in nice clean lines: <?php $wptitle = the_title(); $wptitle = str_replace('&', 'and', $wptitle); echo $wptitle; ?> Now if we look at the ...


4

The simplest answer is as follows: add_filter( 'private_title_format', function ( $format ) { return '%s'; } ); It uses the private_title_format to change the format of the title to just the post title, without any unnecessary classes or functions.


3

the_title() will echo the title for you and can only be used within 'the loop' https://codex.wordpress.org/Function_Reference/the_title get_the_title() without the echo or <?= will simply return the title. So you could store it in a variable and manipulate it if you needed to https://codex.wordpress.org/Function_Reference/get_the_title


3

If you have only ID of a post and you want only the title of that post, then using get_post_field will be best way to do this, I guess. The syntax of this function: get_post_field( $field, $post_id, $context ); So code, that will solve your problem looks like that: $title = get_post_field( 'post_title', $POST_ID ); // most probably you want to display ...


3

Welcome the the WordPress Stack Exchange and congrats on your first post! First off, you may not want to use query_posts() here. Second off - the_post() needs to be before the_title() as it sets up all the posts functions such as the_title(), the_permalink() etc. and queues the next post in your while loop. Your Loop should look like this: <?php ...


3

In addition to moraleida's answer, here's a shorter way to match and output your titles. Note - It will split the string on the first match it finds so if there are multiple '|' or 'em dash' characters, that could be a problem (even for your original code). function gg_short_title( $title ) { if ( 1 === preg_match( '(&#8212;|&#8211;|&#124;|-|...


3

Making Milos's comment into an answer.... The problem you are facing is the result of many wordpress template oriented functions expect some global variables. In WP_Query based loops setting those variable is done by calling the the_post() method of the WP_Query object, but with get_posts you need to call setup_postdata() for that. My personal preference ...


3

There's a few ways to do this, but I would argue that the preferred way is, in general, fetching the post_title attribute from the post object. This does not depend on removing all filters for a certain function and adding them back later — the latter requires you to directly access the global $wp_filter. get_post retrieves the post object for a post ID, ...


3

You have 2 options: Use ellipsis by pure CSS Add this rule to your CSS file. This will add ... whenever the title is longer than its parent DIV. .FacetFeatured a{ white-space: nowrap; overflow:hidden; text-overflow:ellipsis } .FacetFeatured{ max-width: 100px // Change this to fit your grid } This is only done by using CSS. Strip the ...


2

The global $post object exists already for singular views before wp_head is called. It is just not filled with all data. The the_title() calls get_the_title() which in turn calls get_post(). And that calls $GLOBALS['post'] if no post ID has been passed. See also Generating the ogp tags in theme for a use case.


2

This kind of works but it is outputting 1 post title in particular and for all the images on the page. Any thoughts as to why its not dynamically picking up each images associated post title? $attachments = get_posts( $args ); foreach ( $attachments as $image ) { // Get the parent post ID $parent_id = $image->post_parent; // Get the parent ...


2

Try <?php echo get_the_title(1).': '.single_term_title('', false); ?> From the Codex the second argument of single_term_title determines whether to "Display the title (TRUE), or return the title to be used in PHP (FALSE). Default: TRUE"


2

Try this as your query: $args = array( 'post_type' => 'press', 'posts_per_page' => 20 ); $wp_query = new WP_Query( $args ); while // etc. Also you could try: <div class="press-title"><?php echo get_the_title(); ?> </div>


2

You have a few issues here remove_filter( current_filter(), __FUNCTION__ ) is used in wrong context here for what you need to do. remove_filter() unsets the filter from the GLOBALS array once the filter has run once, so your filter is removed after the first run. This happens with spaghetti functions. You should always return the default filter (or some ...


2

The function the_title() is just a wrapper around the function get_the_title(). It's understandably confusing that the filter the_title actually exists inside get_the_title(). So, whatever the function you're using to actually display it, it doesn't matter, you can filter its content by hooking into the_title


2

the_post_thumbnail() and get_the_post_thumbnail() will output the complete HTML for displaying that image. So this <img class="img-responsive" src="<?php the_post_thumbnail(); ?>" alt=""> will be rendered to something like this <img class="img-responsive" src="<img src="..." alt=".." class="..">" alt=""> which is not valid HTML ...


2

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


2

If you refer to the post title you need to hook your function to the_title filter like explained in the codex. add_filter('the_title', 'my_custom_title', 10, 2); If you refer to the HTML meta in your page then you need to hook your function to document_title_parts filter explained here. add_filter('document_title_parts', 'my_custom_title', 10, 2); The ...


2

There's a second argument passed to the_title filter, which is the ID of the post the filter is currently operating on. This is important, as you've discovered, because the filter runs any time a title is output- in a menu item, widget, any secondary query, etc., so you need to check if that post ID matches the ID of the post you're currently viewing. Your ...


2

You are using the default page loop and it will output the current page attributes like title or other. You should create your own loop with custon query instead. See WP_Query or get_posts. Example $query = new WP_Query(array( 'post_type' => 'post', 'posta_status' => 'publish', )); if($query->have_posts()){ while($query->have_posts())...


2

Like this: 'alt' => get_the_title(). ' review' So the full code would be: <?php the_post_thumbnail('250px', array('class'=>"review-siteshot", 'alt' => get_the_title(). ' review' )); ?>


2

<?php echo substr(get_the_title(), 0,42) ;?> Notice the echo and the get_the_title() This will get you the result you're looking for. Here's an alternative to consider: I've always found character limits cause weird word breaks that users find confusing. WordPress has a function called wp_trim_words that you can use. <?php echo wp_trim_words(...


2

single_post_title() and get_the_title() work completely differently. get_the_title() (or the_title(), which works the same) will get the title for the current post in the loop: <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title(); endwhile; endif; ?> So it's the function to use to get the post title for ...


1

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); the_title( '<h3>', '</h3>' );// puts the title in h3 tags the_content(); // adds the content endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?> Notice that you can use the title function where you ...


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