< Php Echo The_title()
< Php Echo The_title() > https://tinurll.com/2tKSkF
Unable to work out a solution to this. I have set up a custom template for my wordpress theme and am trying to change the bit where there is currently an echo of the category link and title to an echo of the title of the post.
This function also uses get_the_title() to retrieve the title of the post, but the final data that is returned is different from the_title(), primarily in that it is escaped. What does this mean? It means that it is safe to use inside of element attributes. It also strips all tags.
The usage of the_title() in attribute tags has actually caused my huge headaches with Easy Digital Downloads. We use the the_title filter to add Schema.org micro data to products, which is excellent because the data is used by search engines to enhance search result entries with product data (price, rating, etc). The problem is that we get at least one support ticket every week from a user that has broken HTML markup (like that pictured above). The problem is prevalent enough that we are being forced to add an option to disable our schema.org micro data.
I think you're probably running into some of the idiosyncrasies of Wordpress here. the_title(), by default, just prints out the title and returns nothing. In order to make it return the title string instead of printing it, you have to set the third parameter of the_title() to true.
The functions works like the_title(), but uses the title with Relevanssi highlights included from $post->post_highlighted_title, if one is available (if not, the function falls back to $post->post_title).
Set the third parameter $echo to false in the the_title() function. By default, the_title() function echoes the title. Third parameter can be used to set echoing to false, and return the title instead:
WordPress the_title function retrieves the title of the current post. It is able to fetch the post with an optional HTML marker up. The marker up can be passed as string parameters of the the_title() but get_the_title() retrieves the post title using optional post id, the id of the specific is passed as a parameter, get_the_title default post id is zero means most current post title.
From what I have seen through reading various discussions on the forums, blogs, and WordPress developer official website, the main difference between the_title and get_the_title is echoing. the_title is echoing a title automatically but you need to echo get_the_title to fetch the title of a given post.
the_title() should only be pulling the area filled out in the TITLE section of WordPress, not any SEO titles from Yoast or other plugins. For extra SEO bonus, the H1 page title and SEO title displayed in Google/Bing should be different. They're different audiences. One "searching" for something, the other is already on your site.
And did you see how echo outputs not only text content, but rather HTML markup? In other words, our echo contained both regular words, and an HTML tag to surround them and make them italic. When we tell PHP to echo those things, they both get printed straight onto the (web)page as pure HTML, and the result is two words of italicized text.
Also, the_title() should be the_title(false). By default the_title (and other "the_" functions) echo out the value rather than return it. the_title(false) returns the title so you can use it in your echo statement.
Add the function below to your functions.php file (if you don't have a functions.php file refer to the introduction paragraph). To print the shortened title use ' echo ShortenText(get_the_title());'. This method provides an ellipsis option which is used only if the length is longer than the designated '100' characters. The ellipsis can be changed to any text for Example: 'read more >'. 781b155fdc