-1

I want to dynamically implement the h1 into the page title. The end-users won't have access to the source code but will be able to add headings (such as h1). I need the title to be filled with the content of h1. How can I do it? I want to do it for Wordpress, as I create my own template.

<title><?php echo h1 ?></title>
<h1>The Title</h1>

Again due to many inaccurate answers: the USER has NO access to the code. He uses only the editor, where he can place TEXT and headings. He has no knowledge of coding, so whatever he types in as heading1 will need to be a title. No variables on front end whatsoever. The backend will need to stay generic.

This is what the user can access: user's access

He puts in the Title of the page. I want this title to become a < title >, not only a H1, which Wordpress offers.

Thanks

Piotr Ciszewski
  • 1,691
  • 4
  • 30
  • 53
  • Here, [this answer](https://stackoverflow.com/a/9628266/3536236) looks like it does what you want, you will have to give it a try but it seems promising. – Martin Apr 27 '20 at 21:19

2 Answers2

0

get_the_title() will probably be the way to go and should work as you are in the context of "The Loop" when working with a post template.

Use it like this:

<h1><?= get_the_title(); ?></h1>
flomei
  • 860
  • 1
  • 11
  • 36
  • as I mentioned - the end user has NO ACCESS to the code. He can place only headings and text. So this won't work. He will use only text editor embedded into CMS. From that editor the H1 will need to be the title – Piotr Ciszewski Apr 24 '20 at 13:29
  • So, what's the problem then? If the editor has capabilities to place headings (the editors in WP have that), why would you even do something like this in the theme, when the user can do it through the editor? – flomei Apr 24 '20 at 13:49
  • yes, but the user doesn't know the code at all. He will be copying and pasting the text + selecting headings. I can't ask people who barely use the computer to place PHP code. There will be a simple text field with some options like in word. The user has no idea what is h1, h2 or anything like that. He just formats text and by selecting which part of texts will be h1, it will automatically be copied to the title. – Piotr Ciszewski Apr 24 '20 at 13:59
  • So, maybe you should look into shortcodes instead? Maybe the user can do something like `[headline]My headline[/headline]` and you can handle that through the shortcode API? – flomei Apr 24 '20 at 14:03
  • not really, I don't like using walkarounds for end users. It must be kept as simple as possible with absolutely no keywords to remember. I can do it with jquery, but prefer to use PHP to avoid loading up external files. – Piotr Ciszewski Apr 24 '20 at 15:25
  • Still don't get it. What can the user enter and what not? Can he use some kind of shortcode? How is the editor (or the logic behind it) supposed to know what's the headline? Is it an extra field? Something else? You should really clarify your post, as it's not clear at all. – flomei Apr 25 '20 at 15:06
  • I have updated my question with one image. I hope it will make everything more clear. The user has access to the text editor. On top of the editor there is a place to put Page Title, however this will not become a but just h1. I want this field to affect the <title> of the page. – Piotr Ciszewski Apr 27 '20 at 20:55
0

Create a variable with the content of h1. Then echo out that variable.

For example

<?php

$h1_the_variable = "Hello world!";
echo "<title><h1>" . $h1_the_variable . "</h1></title>";

?>

Learn more about variables : https://www.w3schools.com/php/php_variables.asp .

Learn more about echo : https://www.w3schools.com/php/php_echo_print.asp .