Removing wordpress theme from particular pages - wordpress

I have a custom Wordpress theme that includes a header, footer, and a few other elements. It's great, but there are a few pages that I want to style completely differently. One of them is, for example, a landing page, where having the typical header makes no sense. How can I tell Wordpress not to use any themes on this page? Is this even possible?

You can use Page Templates
For example, if you would like to use custom header or footer for your landing page you can do following in a separate .php file and declare it as a Page Template.
I'm assuming your header and footer file name header-landing.php and footer-landing.php
<?php
/**
* Template Name: Landing Page
*/
get_header( 'landing' ); ?>
// Landing Body
<?php get_footer( 'landing' ); ?>
If you wish no header or footer then, you can just omit get_header() or get_footer() function call.

You can use conditionals to decide when to load certain stylesheets onto certain pages.
For example, in your functions.php, you can use wp_enqueue_style to load in different stylesheets. In your php, you would say something like this:
function custom_page_style_sheet() {
if (is_page() ):
wp_enqueue_style( 'custom-page-styling', get_stylesheet_directory_uri() . '/custom-page.css' );
}}
add_action('wp_enqueue_scripts', 'custom_page_style_sheet');
Try this tutorial, which is where I grabbed the example code from:
http://wpsites.net/wordpress-themes/second-style-sheet-theme/

Related

Convert one page website to multiple wordpress pages

I have a working one page website I like to convert into multiple pages in wordpress.
I already successfully created a theme, converted the header, footer, css, js into wordpress, header.php, footer.php, and functions.php by following a tutorial.
Now I'm left with all my html content between the header and footer and want to cut that content up into multiple wordpress pages.
I can do "the_title(); wrapped in php" and make the content while loop to get the first page into a wordpress page, but from then I dont know what to do, to split the next lines of html into other wordpress pages.
You will need create some page templates for your theme. They will look something like this:
page-about.php
<?php
/* Template Name: About Page */
get_header(); ?>
... about page content
<?php get_footer(); ?>
page-contact.php
<?php
/* Template Name: Contact Page */
get_header(); ?>
... contact page content
<?php get_footer(); ?>
Then assign the template in the Wordpress admin, on Edit Page view to the corresponding templates you want to use. You select the template by the name you give it in the comments.
The actual file name of your templates matter. Some views in wordpress are assigned to templates simply by the name of the file. So you will want to use certain naming conventions like page-about.php. More info about templates: https://developer.wordpress.org/themes/basics/template-hierarchy/

Wordpress body_class() loads single post css on a blog page

On my blog landing page the body_class() injects the blog style (http://madgreens.com/blog). But, when a blog page loads, the single-post style is injected (http://www.madgreens.com/blog/2015/02/chicken/).
I did upgrade 4 plugins recently but have moved them to a folder 'plugins-temp' until I sort this out.
Is there a way to force Wordpress to load the correct css on all blog pages?
That is the default behavior of body_class(). If there are other classes that you want in addition to the standard classes, you can add them by:
body_class( 'classname' )
or
body_class( array( 'classname1', 'classname2' ) )
So if there is some class you always want, just modify the body_class function in your template to include it.
For more control, you can add a filter in your functions.php file, like so:
function enhanceBodyClass($classes)
{
global $post;
// Add any classes you want to the $classes array
return $classes;
}
add_filter('body_class', 'enhance_body_class');

wordpress wp_enqueue_style on page that doesnt include get_header

I have created a plugin which has it's own custom page template. I dont want this apge to use the default themes css, so have excluded get_header(), and used the following which just pulls in the wordpress functionality
require_once('../../../wp-load.php'); global $wpdb, $woocommerce;
My problem now is i am trying to enqueue a style, but as my template is not including get_header() or wp_head() it doesnt look like it is working. Is there a way around this?
I am using wp_enqueue_style like this:
function woops_styles() {
wp_register_script('packing-slip', plugins_url('/my-plugin/style.css', __FILE__));
wp_enqueue_script('packing-slip');
}
add_action( 'wp_enqueue_scripts', 'woops_styles' );
You will need to include wp_head(), so you will need to have a header. wp_enqueue_scipts hooks on wp_head().
What I would suggest if you need a diffirent styling for this page is to assign a body_class() to this page and then style that accordingly. You can use a conditional statement (is_page_template()) to only assign the body_class() to this specific page template.
If you really don't need a header to show up, simply hide it with css

Using get_tmplate_part() function in Wordpress

I am making a wordpress theme, in which I have different skins and templates, Is it a good idea to use get_template_part() function to load different chunks/templates instead of having one single file. I find it useful however my only concern is, will this function put load on server or effect the performance in any way ? I am using it like below:
/* Post Tags Template */
get_template_part( 'templates/post_tags' );
/* Post Meta Template */
get_template_part( 'templates/post_meta' );

How to change header in Wordpress Blog page and all Post pages only

How to change header in Wordpress Blog page and all Post pages only.
I want a custom header in Blog page and all single posts page.
Thanks
You can use conditional tags within Wordpress:
http://codex.wordpress.org/Conditional_Tags
Basically, you will need to create the content you want only for the blog and post pages and wrap this within the conditional tags:
P.S Don't forget to include the category, and archive pages - as well as the post pages.
is_single(), is_archive(), is_category()
<?php if (is_single()) { ?>
// This is a post page
<?php } else { ?>
//This is not a post page
<?php } ?>
Hope this helps.
To include different header for specific pages change get_header($name) function call inside templates and add $name attribute. Wordpress will load header-{name}.php if file exists, if not, default header header.php will be loaded. Check out template hierarchy for templates where you need to change get_header() function call ( single.php, page.php ).
Wordpress documentation:
get_header
template hierarchy

Resources