Wordpress Universal Header Footer Overriding Site Navigation & Footer - php

On Azure hosted Wordpress site I have to use a Universal Header/Footer (UHF) which when activated overrides the sites header/footer.
I require the sites original Navigation and added Footer code to run.
These are the README.md instructions:
Theme integration
Once UHF has been configured, minor changes need to be made within your site's theme(s):
Begin by wrapping the theme's current header in a Microsoft\UHF\is_active() conditional statement. This helper method will determine if UHF is configured and active for the current site. Meanwhile, your existing code will be in the else portion of the conditional, enabling your site's current functionality to persist should UHF ever be deactivated.
Example:
<?php if ( function_exists( '\Microsoft\UHF\is_active' ) && \Microsoft\UHF\is_active() ) : ?>
<?php \Microsoft\UHF\get_header(); ?>
<?php else : ?>
<!-- Your original header -->
<?php endif; ?>
Please note that the UHF header should be the first thing under the <body> element, but it does not replace your existing <head> element!
The footer replacement will be similar:
<?php if ( function_exists( '\Microsoft\UHF\is_active' ) && \Microsoft\UHF\is_active() ) : ?>
<?php \Microsoft\UHF\get_footer(); ?>
<?php else : ?>
<!-- Your original footer -->
<?php endif; ?>

The provided code samples show how to replace the header and footer with UHF's (when the feature is activated), but if you need the UHF header and/or footer and your original header/footer, you can adjust the conditional statement, e.g.:
<?php if ( function_exists( '\Microsoft\UHF\is_active' ) && \Microsoft\UHF\is_active() ) : ?>
<?php \Microsoft\UHF\get_header(); ?>
<?php endif; ?>
<!-- put your header here, outside the conditional -->
Source: I wrote the plugin.

Related

Need Help Hiding Sidebar on Custom Wordpress Php file

I am using the underscores theme to build my wordpress site. It is very barebones (which I like), but they didn't seem to include a page.php and post.php file, instead they just have page. This means if I have a sidebar, it shows on all pages and posts. The code to show the sidebar is
<?php if ( ! is_active_sidebar( 'sidebar-1' )) {
return;
}
?>
I've tried a number of if statements to exclude pages but I can't seem to get it right. How would I have it so if the person is on a page it doesn't return the sidebar?
Thanks!
Edit the page.php and REMOVE the sidebar:
<?php dynamic_sidebar( 'sidebar-1' ); ?>
or the get_sidebar() function.
get_sidebar();

Include a custom carousel to show it only on the home page

I have a custom carousel that I want to show only the home page. I've placed the carousel's code a file called slider.php I can get the slider to show when I include it inside the header.php file:
<?php require('../BlueQuote/wp-content/themes/greatmag/slider.php'); ?>
But when I place it in index.php or in home.php it's not showing up on the page (for curiosity I've tried including it inside footer.php and it does show up there as well, but that's not what I need). I'm using a child theme, based on the GreatMag theme. WordPress 4.9.4 and PHP 7 with XAMPP on Windows 7, thanks in advance!
I tried to debug this theme and found the following.
Header.php will force this to show on every page that uses a header (so this won't work), and index.php is a generic template file and is used to display a page when nothing more specific matches a query (so this won't work too).
So you have to edit only home.php file. Add this code after the php function and right before the content area div. This is a snippet of the part:
/.../
} else {
$cols = 'col-md-8';
}
?>
<!-- This is where your code starts -->
<?php require('../BlueQuote/wp-content/themes/greatmag/slider.php'); ?>
<!--- This is where your code ends -->
<div id="primary" class="content-area <?php echo $cols; ?>">
<main id="main" class="site-main">
<?php
if ( have_posts() ) : ?>
<div class="<?php greatmag_blog_layout(); ?>">
<?php greatmag_grid_sizer(); ?>
/.../
This should do the trick, because you were trying to add code to a wrong part.

Custom WordPress template loads only header & footer

I have a weird problem. I'm trying to make custom template for WordPress.
index.php works perfectly fine - everything what should load, loads with no problems.
index.php:
<?php get_header(); ?>
<?php if ( is_home() &&function_exists('get_template_part')) get_template_part( 'content', get_post_format() );?>
<?php get_footer(); ?>
But when I create a new page, like promotions.php and put custom code, It does not show up on the page. I can see only header & footer section. It looks like I didn't put any code at all.
You can make custom page templates like so
<?php
/**
* Template name: custom-name
*/
get_header();
if (is_home()) {
get_template_part('content', get_post_format());
}
get_footer(); ?>
And then inside WordPress you can edit the page. On the right side below publish you can see default template. Choose your template and hit save.
Edit:
See the image below for further instructions.
Use flush_rewrite_rules() function one time in functions.php.
All should works after that.

Custom post_type template with get_template_part

So, my parent-theme uses a single.php calling a content-single.php with the function get_template_part().
The code for single.php:
get_header(); ?>
<div class="container">
<main id="main" class="postItem" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php codex_coder_content_nav( 'nav-below' ); ?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
<!--<?php get_sidebar(); ?>
I am using a custom post_type named "ourNews". Following wordpress documents, I created two files: single-ourNews.php and content-single-ourNews.php
With this, in my "single-ourNews.php" I changed the following line:
<?php get_template_part( 'content', 'single-ourNews' ); ?>
But it keeps loading the file "content-single.php". What am I doing wrong?
Other question is: How can I put a image with relative path on this custom template? I created a folder "img" and I was calling using:
But says that the image was not found. I read a little and some places said that I could not use relative path, but why not, if the theme uses? I'm confused.
Wordpress is still loading single.php that loads content-single.php
Your custom post is not ourNews. This is probably the label but not the slug. The slug is always lowercase and separated by a -. Try renaming your file to single-our-news.php.
Also, every time you register a custom post type, you should reset your permalinks options back to default and then back to what you want it to be.
For the relative path, you should not use it. You should use .'/img/name-of-image.jpg
When using get_template_part, the first parameter defines the base template name (e.g. content, which loads content.php) and the second parameter loads a suffixed version if available. Therefore your call
get_template_part('content', 'single-ourNews');
is looking for a file named content-single-ourNews.php first, then falls back to content.php in case the first one is not available. I'm not sure whether the get_template_part function converts the suffix parameter to something like single-ournews or single-our-news before appending it to the first parameter, be sure to test a few variants of that.
I'm not 100% sure if the function behaves differently or not in child themes and parent themes. One option is to override the parent's single.php in the child theme and modify it directly with
if ($post->post-type === 'ourNews') {
get_template_part('content', 'single-ourNews');
}
else {
get_template_part('content');
}
Lastly, WordPress will look for a file single-[cptslug].php before loading a template for a custom post type's single view.

Adding your own custom page to Wordpress with its own custom script

I wish to add a custom page to wordpress, not in the usual sort of way. This page has my own custom script and functions and to develop a plugin is beyond my means so I was wondering if this is possible:
Suppose I were to build it on the existing page.php script in my there folder, my script looks something like this:
<?php get_header(); ?>
<div id="left-area" class="clearfix">
<?php
//My script would go here
?>
<div class="comments">
<?php comments_template('',true); ?>
</div><!-- end of comments div -->
</div><!-- end of left-area -->
<!-- LEFT AREA ENDS HERE -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Is this even possible? I tried and got a page not found error. And if so, how do I call this script assuming WP is installed in the root directory? Example: www.mysite.com/myscript
Absolutely. Duplicate page.php. Rename it to template_mine.php. Open to edit, and before the get_header tag, add:
<?php
//
// Template Name: My Custom template (choose something more descriptive, like contact page)
//
?>
Go to Wordpress dashboard for pages, create a new page with your title, and in the Page attributes on the right hand side, under templates, select your template name, update, and you are all set.
Reference: http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

Categories