Wordpress and PHP includes - php

If I was looking to use my own HTML for a certain page on my wordpress theme, how can I go about it?
Please advise where code should go
If I can use raw HTML or PHP INCLUDES.

If you are looking to place the HTML in the main page content, just use the text editor of WordPress(http://www.wpbeginner.com/glossary/text-editor/). The header & footer would be modified inside the header.php and footer.php files of your theme. the directory where these would be located should be /wp-content/themes/salient/. If you want the header and footer to only be modified only on specific pages, you will want to use the is_page() function built into WordPress(https://codex.wordpress.org/Function_Reference/is_page).
Example of limiting header or footer modification to specific page:
<?php if( is_page( 42 ) !== false ) { ?>
<!-- HTML that should only appear on page with id of 42. -->
<?php } ?>

Related

Hide wp_head () only in the homepage

I've this code in the header Homepage that find automatically the title page for homepage and the posts how title tag. But I've my personal title tag only in the home page. The source code show 2 title tag in the home.
How can I hide this code in the home?
<? php wp_head(); ? >
i think, you can use the "is_home()" and "is_frontpage()" function, depending on how your frontpage is setted up in theme (static page, blog page...), one of them or using logical and can be necessary.
with this you can do like:
<?php
if( !is_home() && !is_frontpage() ) {
wp_head();
} else {
// custom head code
}
?>
an other way is using a separate template for home/frontpage (using a frontpage.php/home.php), where you put in your code.
here the difficult for me was to learn how wordpress is using more specific templates and templateparts (like using get_header('home') to use header-home.php instead of header) and with which weight-order they are used.
https://developer.wordpress.org/reference/functions/is_home/
https://codex.wordpress.org/Creating_a_Static_Front_Page
is_front_page() & is_home() can't help you ?

Wordpress displaying the header and footer on all pages

Is there a way I can make the header and footer appear on all pages without placing get_header(); or get_footer(); in each of the separate page files? Is there something I can do in the loop or somewhere else that automatically does this?
You want to show get_header() and get_footer() to all the pages. For that you just mention get_header() and get_footer() in each custom template you have created. By default you can place it inside page.php file.
Also if you want to use custom header and custom footer , then you need to create header-custom.php and footer-custom.php file and call them inside any template like the following.
get_header('custom');
get_footer('custom');
It works with just placing them in the page.php file of your theme.

Customize static wordpress pages correctly

I m building a word press site with a unique theme that i created, now i got like 10 classes of different styles for the static pages in my site.
The question is, when i want to display the content of the page, with all the forms images and text, how should i do that? With the text editor where the user usually insert his content for the posts in regular wp website? Or should i insert the content images and forms hard coded in the php custom page template of those static pages?
In the text editor if i insert some html in edit as html it's becoming a mess it doesn't seems right to create sections and div where the user regularly just put his raw content, and anyway adding more content to a static page in the future will require my intervention to wrap it with css sections and div's definitions and classes...
By the other hand to write raw data with images and forms in the php custom page template doesn't seems to me the right choice... Is it normal to do so for static pages?
Thanks everyone!
Wordpress static pages, by default contains text and images that you can put into it using the Wordpress text editor. This content is known as "The Content" in WP context.
If you want to put into your static page some elements that cannot be setted by the text editor (like your own forms, per example) you'll need to create your own page template with hard-coded elements.
Example:
<?php /* Template Name: My custom page template */ ?>
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="article">
<div class="date"></div>
<!-- Your own custom content here -->
</div>
<div class="clear">
<?php if ( comments_open() ) : ?><div id="comments"><?php comments_template('', true); ?> </div>
</div><?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
<?php get_footer(); ?>
I normally will put those styles into styles.css of your theme. Even if it's images that will be standard images for the theme or shortcodes available to the user you want it to load from within the styles.css page. You don't want to do anything static like that with WordPress. Updates can mess it up as well as having issues with inline css messing up your SEO for the site.
If the user needs to do something in the editor to have an image show or something like that you can do it as a shortcode. That's normally going to be your best approach. Have you used shortcodes and loaded the images that before?

Wordpress include meta tag in theme header on a custom template page

I have a template page I have created myself. On it, I add the header used in the WordPress theme using:
get_header();
However, in it, only on this page, I need to add HTML tag. If I add it after the above code, it is not in the section. I do not want to add it to the theme's header, because, as I explained, I do not need this meta tag on other pages. Also, I do not want to copy the whole header in my template's file, as this is duplicate code and it doesn't seem right to me.
Put the changes in your header.php by using conditional tags.
For example, in your header.php, add something like this:
<?php
if (is_page_template( 'templates/YOUR_PAGE_TEMPLATE.php' ) ):
//Your code goes here
endif;
?>
You can use other conditional tags to suit your needs.

Convert html to wordpress & provide link to menu inside panel

I have an HTML template which I am trying to convert into PHP for WordPress.
The homepage has been converted and is shown properly. Next, the menu in navbar is about, the page that needs to be converted in PHP.
I have just added get_header() at the top and get_footer() below. In between these two I have added the HTML content for my entire page.
Then I tried to provide the link for the menu that I created, but the content of about page is not visible.
Do I need to add any other line for that page apart from get_header and get_footer? Or is something wrong with the link?
Clearly I can't understand what your are trying to say. I think you want to create a page that will show your about menu content.
So in your theme directory create a page name page.php and use get_header(); in first and below get_footer and where you want to show page content write the_content();. like this
<?php
get_header(); ?>
<div><?php the_content(); ?></div>
<?php get_footer(); ?>
after that follow the url of # Sajid Anwar. because for dynamic data you have to create pages(home,about etc) from wordpress dashboard and in menu section add these pages as navigation menu to menu.

Categories