最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Uppercase first sentence in every post

programmeradmin3浏览0评论

Brand new to this community but been tinkering with WordPress for years.

I would like to edit my website's functions.php file to be able to automatically do a task I have to do manually each day.

Basically, everyday I write a discussion with 5-20 paragraphs. At the beginning of each paragraph, I always lead with "PARAGRAPH TITLE HERE..." (without the quotes), so the discussion looks like this:

WHO LET THE DOGS OUT... Paragraph text here describing who actually let the dogs out. I wonder who let the dogs out. Long paragraph text here.

I AM EATING A RAISIN... Yes, raisins are supposedly good for you. Lots of sugar, but good. Raisins are made from grapes.

Basically, I want the functions.php file to make the words before the three dots uppercase in every post I do. What is the most effective way for me to accomplish this? Thank you!

Brand new to this community but been tinkering with WordPress for years.

I would like to edit my website's functions.php file to be able to automatically do a task I have to do manually each day.

Basically, everyday I write a discussion with 5-20 paragraphs. At the beginning of each paragraph, I always lead with "PARAGRAPH TITLE HERE..." (without the quotes), so the discussion looks like this:

WHO LET THE DOGS OUT... Paragraph text here describing who actually let the dogs out. I wonder who let the dogs out. Long paragraph text here.

I AM EATING A RAISIN... Yes, raisins are supposedly good for you. Lots of sugar, but good. Raisins are made from grapes.

Basically, I want the functions.php file to make the words before the three dots uppercase in every post I do. What is the most effective way for me to accomplish this? Thank you!

Share Improve this question edited Aug 11, 2020 at 5:24 Nate Allen 2,1062 gold badges16 silver badges23 bronze badges asked Jul 31, 2020 at 21:47 radioman10radioman10 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

Welcome to WPSE.

So I can't write all the code for you, but I would suggest you look at these main pieces, and then come back here or make new questions if you have followup questions:

  1. To alter the content of a post before it's printed to the screen you could use the the_content filter. This lets you make any changes you want at all to the content section of a post (or page) before it's printed to the screen, and return it with any changes to wherever is trying to print it.

  2. Then you have to find the part you want and only change that part. This is more of a PHP question, but for example this snippet of code will take a string with ... in it and split it into two pieces around the ...:

$content = "TITLE HERE... Once upon a time";
$pieces = explode("...", $content, 2);
// now $pieces is a PHP array with anything before "..." in $pieces[0]
// and anything after "..." in $pieces[1]
  1. Then you need to convert some of it to upper case, probably using the PHP function strtoupper() and put it back together. E.g. continuing from above:
$new_content = strtoupper($pieces[0]) . "..." . $pieces[1];

Note: It's not a very clearly drawn line, but Item 1 is the main WordPress part, Items 2 and 3 are more PHP questions which should be directed to e.g. stackoverflow.

HTH and happy to help further, to make best use of this StackExchange is best to make a start on some piece of the code and ask specific questions about where you get to.

发布评论

评论列表(0)

  1. 暂无评论