Replace word on template page with page title in php

Now I'm starting to understand the endless ways a person can use php.

I created a template page called new-member.php that calls the content from another page, so when I add a new element, it's quick and easy.

Now I use the following path:

  • I am adding a new page with the company name as the name.
  • I choose a new member template.
  • Click Publish. This will create a β€œnew member soon” page, which in a few seconds. Excellent!

But I would like to go to a higher level and replace the "New Member" php function with the page title (company name) so that when adding a new page not only new members of the url, but instead of saying "New Member coming soon", he says "XYZ Coming Soon!" which is a temporary page until an official one is created.

Can someone please show me the correct code and where to place this code? I am using wordpress. I do not know how to write this code. Is the code included in the new member.php template? Heading? I have no idea, but I want to study!

Please, help!

+4
source share
3 answers

What you need to do there (if I were in your place, I built a plugin or performed some functions. Hacking), it will capture the output of the included page and replace your specific "New Member" tag with what you need. In the example below, I'm going to use %NEW_MEMBER_NAME% instead of "New Member", which makes your replacement string more unique, so on your wp placeholder page you will write

"% NEW_MEMBER_NAME% comig soon".

 <?php /* Template Name: New Member */ ?> <?php get_header(); ?> <div id="primary"> <div id="content" role="main"> <?php the_post(); // i don't think you need this anymore // get_template_part( 'content', 'page' ); ?> <div class="entry-content"> <?php if(function_exists('iinclude_page')) { ob_start(); iinclude_page(112); $content = ob_get_clean(); echo str_replace('%NEW_MEMBER_NAME%',the_title('','',false),$content); } ?> </div> </div><!-- #content --> </div><!-- #primary --> <?php get_footer(); ?> 

Remember that it’s never a good idea in your templates to hard code things, as you are doing here with β€œ112”, the id of your wp placeholder page and, presumably, the replacement tag% NEW_MEMBER_NAME%. You must branch out the theme and create an administration settings page for the two.

Hope this is for you in some way.

+1
source

Modify the newmember.php template file. Find "The Loop". Your email content is displayed here. Change the name.

http://codex.wordpress.org/Function_Reference/the_title

 //syntax <?php the_title( $before, $after, $echo ); ?> //add this to your newmember.php template <?php the_title('<h3>', '</h3>', true); ?> 

If you post what is in your newmember.php template file, a more specific answer may be provided. But this is simple enough, I think you can probably figure it out yourself.

0
source

Not sure. If I understand your question correctly. But here is what I think you might have to do.

Just replace

 New Member coming soon 

with

 <?php the_title();?> coming soon 

Now you will get the name of the page instead of "New Member".

0
source

Source: https://habr.com/ru/post/1387142/


All Articles