I am trying to make my website mobile friendly and it works when using inside head
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<?php $this->head(); ?>
</head>
<body>
<?php $this->beginBody() ?>
<?php echo $this->render('//layouts/_top_js'); ?>
<?= Alert::flashes() ?>
<?php echo $this->render('//layouts/_header'); ?>
<?= $content ?>
<?php echo $this->render('//layouts/_footer'); ?>
<?php echo $this->render('//layouts/_bottom_js'); ?>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>
But when I start using the following code:
php $this->beginBody()
php $this->endBody()
it is completely ignored. Is the viewport code disabled when using the php code to load my pages?
The viewport needs to be explicitly set in the <head> section of your HTML. You should start the page with beginPage() instead of beginBody(), as the second one only renders the <body></body> part of the HTML.
PHP only outputs HTML on the page, in the case of Yii using layouts.
You need to check your layout files to make sure they contain the following line:
<meta name="viewport" content="width=device-width,initial-scale=1">
Related
Guys, I have a problem. Is there a way to add html inside a tag without using javascript using only php anyway ?. Thank you very much for your help in advance.
For example, there is this code:
<?php
// This part is required here, because she comes another function.
// It's generate from php server, I need to show inside tag body, for example.
$code = "<h1 style='display:none' id='title'>My String</h1>";
echo $code;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<div id="my-div"></div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js'
integrity='sha512-b6lGn9+1aD2DgwZXuSY4BhhdrDURVzu7f/PASu4H1i5+CRpEalOOz/HNhgmxZTK9lObM1Q7ZG9jONPYz8klIMg=='
crossorigin='anonymous'></script>
<script>
$('#my-div').html($('#titulo').html());
</script>
</body>
</html>
The output is this in the source code:
In the browser, the output is this My String:
But, this manipulation is the gift, which uses javascript for this. I don't want it that way. This will not do, because the code will be shown at the top, before the <! DOCTYPE html> tag. Is it possible, on the server, to insert <h1 style ='display:none' id='title'> My String </h1> inside the boby tag, for example?
How I would like it to look:
Example 2
For example, I have this file with code:
file2.php
<?php
include "file2.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<div id="my-div">
I want to show "<h1>My String</h1>" here.
</div>
</body>
</html>
Yes you can do it as simple as this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<div id="my-div">
<?php
$code = "<h1 style='display:none' id='title'>My String</h1>";
echo $code;
?>
</div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js'
integrity='sha512-b6lGn9+1aD2DgwZXuSY4BhhdrDURVzu7f/PASu4H1i5+CRpEalOOz/HNhgmxZTK9lObM1Q7ZG9jONPYz8klIMg=='
crossorigin='anonymous'></script>
</body>
</html>
PHP is a server side scripting language and will only parse PHP code on the server side.
Yes, you can place HTML code inside PHP variables like you have done, but that will get rendered into the client (your browser).
What you can do is place $code variable inside the target div, like this:
<div id="my-div"><?php echo $code; ?></div>
Give it a try
I am starting with wordpress and after adding dynamic heading <?php wp_head(); ?> everything in the body disappears.
this is my header.php file
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset');?>">
<title><?php bloginfo('name');?> | <?php wp_title();?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="<?php bloginfo('template_url'); ?>/css/bootstrap.css" rel="stylesheet">
<link href="<?php bloginfo('stylesheet_url'); ?>" rel="stylesheet">
<?php wp_head(); ?>
</head>
When I remove the <?php wp_head(); ?> line, everything in the body shows. I am told that including the line is a must in wordpress.
On your header.php you have to call:
<?php wp_head(); ?>
On your internal pages, like index.php you have to call:
<?php get_header(); ?>
See:https://codex.wordpress.org/Theme_Development
Also you can turn your debug mode on in order to identify the errors.
https://codex.wordpress.org/Debugging_in_WordPress
I am looking to translate pages in wordpress if the url contains the language /fr/ in the url. I am testing on a local site where I would like the language to default to french when I create the page http://localhost/fr/.
I would like to do this for multiple languages - for example
`http://localhost/de/`.
`http://localhost/es/`.
index.php
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<?php echo language_attributes();?>
<head>
<meta charset="<?php bloginfo('charset');?>">
<title>Page Title</title>
<?php wp_head(); ?>
</head>
<body>
<h1><?php echo __('This is a Heading','basictheme')?></h1>
<p>This is a new paragraph.</p>
<?php wp_footer(); ?>
</body>
</html>
functions.php
<?php
function basictheme_functions(){
load_theme_textdomain('basictheme',get_template_directory().'/lang');
}
add_action('after_setup_theme','basictheme_functions')
?>
My head content(metas, scripts etc.) appears in the body tag. I have header php with this code
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device=width">
<title<?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<header class="header">
<h1 id="logo">|||</h1>
<h4 id='title' ><?php the_title(); ?></h4>
</header>
<body>
and footer.php is closing it with this. `
<?php wp_footer(); ?>
</body>
</html>`
Already tried changing encoding from UTF-8 to UTF-8 without BOM using Notepad++, and still the same ,, this is my website if you wanna see with inspect [website]
website . Any ideas ? :S
Your html is broken:
<title> Name Lastname / Official Website</title>
^---- missing >
I have the following Layout (called: "MyView.ctp") in /app/view/layouts
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $title_for_layout; ?></title>
<!-- add favicon here-->
<!-- js -->
<?php echo $scripts_for_layout; ?>
</head>
<body>
</body>
</html>
I have the following View (called MyView.ctp) in /app/view
<?php $html->css('fup-prototype','stylesheet', array('media”=>”all' ), false); ?>
The following css file (called fup-prototype.css) in app/webroot/css/
But am getting this error:
What am I doing wrong here?
Instead of
array('media”=>”all' )
you most likely meant
array('media'=>'all' )