Link custom header in Wordpress - php

I am trying to achieve the basic function of using a custom header on my home page in Wordpress.
I am only just learning wordpress but I will try and explain.
So I have both a parent and child theme, the parent theme has a folder called 'inc' with a file custom-header.php ready to tailor.
I have duplicated the 'inc' folder and placed it in my child theme folder.
At the top of page.php file in the parent folder (there is no duplicate in the child folder) I have changed
get_header(); ?>
to
get_header(custom-header); ?>
I have tried making dramatic changes in both the Parent custom-header.php and the duplicate child custom-header.php and nothing happens.
I have also tried changing the file names, for example header-home.php and then calling
get_header("home"); ?>
and this does not work either.
I have put the get_header in the top of the page.php as I think this is where it is served from (with my limited knowledge) and when I try and edit it, the page fails to reload, so I would assume it is the right php file but I am obviously doing something wrong. I have spent quite some time looking but it is suprisingly difficult to get a clear, concise explanation on the right syntax and exactly where I place the get_header code and actually keep the custom header file.
Any help would be great.

The only correct versions you used was:
//file: header-home.php
get_header('home');
Unfortunately for header files, they need to be in the root directory of your active theme (or parent theme if using a child) to be called. i.e. themes/custom-theme/header-home.php
You are correct as in you change the get_header() function in your page files, but dont forget your home page may be front-page.php, home.php, index.php or a page-whatever.php if using a wp page as the front page.

Related

How can i have a pagination on my wordpress website

I'm trying to have a pagination on my custom Products page that is not the default one in Woocommerce.
I used Elementor to customize this page and after some research I saw that I could call a function that is already integrated in WordPress using the < paginate_links > function.
The only problem is that I have no idea where to call this function in order to have a pagination on my product page.
To be more precise, i would like to know where exactly i have to change or add my php functions, and what code should i use to get my pagination.
Normally it is in the archive.php or a version of that file name specific to your post-type. But before you go and change it, create a child theme in case you haven't done that already. In the child theme folder, you then duplicate the archive.php or similar to make it overwrite the one from the parent theme. This way you keep your version of the theme clean and updatable without losing any changes.
(For creating a child-theme you will need to create at least a style.css [with a WordPress-specific comment, you can google] and a functions.php-file that needs a bit of php-code to enqueue the child-themes scripts and styles. The code for the functions.php can also be found by a quick google search. You then just place the style.css and the functions.php into a new folder you name in the pattern [foldername of your themes name]-child. You then place this folder next to the parent-themes folder in the "/wp-content/themes/"-directory.)
And here you go for the pagination: https://codex.wordpress.org/Pagination

How to over-ride a php file from parent theme

I know this question might sound generic, but the answers to those generic questions is not working for me.
I am very new to touching wordpress php files, and I am working for a client using the FitPro theme (I will be posting on their general forum but my client no longer has support :/). I need to change the permalink for the cutom post type defined as "fitness-class" and replace it with "classes".
I found where the slug is defined (it is in a file called custom_post_types.php and it is located at 'framework/presentation/custom_post_types.php'). I confirmed that changing the file of the parent theme achieves the desired affect, however it does not work when I try to replicate it in the child theme.
I copied the custom_post_types.php file to my root directory in the child theme, made the change and it did not work. I replicated the file path of the parent theme and it still did not work. I looked up the problem online and, among others, came across this solution : https://wordpress.org/support/topic/child-theme-fix-use-get_template_part-instead-include-get_template_directory.
My Problem (at least right now): My theme does not appear to have a front-page.php file. Instead there is a file at 'framework/framework.php' that includes the following line: require_once(MO_FRAMEWORK_DIR . '/presentation/custom-post-types.php');
How do I go about over-riding this specifically? There is no get_template_directory call for me to over-ride as far as I can tell as the above solution stated.
I tried commenting out the line and then copying the framework.php file to both my child theme root directory and I tried copying the parent theme file path. I tried adding the get_template_part call to both my functions.php file and the framework.php file. I do apologize if I am clueless here, but I have not yet gotten to the point of learning the wordpress structure.
Any advice is greatly appreciated thank you. I have no idea where MO_FRAMEWORK_DIR is defined, but if I do find it and it solves my problem I will update the question.
Whatever file you have to override from the parent theme then you have to copy this file and you have to put simply in the child theme
For Example if u have to override single.php file of the parent theme. Then you can simply copy the single.php file and put it to child theme.
Create folder in you child theme as below.
framework/presentation/
And under the presentation folder put the custom_post_types.php
I hope you understand.

Wordpress - all pages link to the index.php file

[NEW AT WORDPRESS]
I'm creating my own wordpress theme with own css etc etc. I've managed to get everything good in the index.php file, and I'm trying to make the other pages as well now.
When I make the home.php, blog.php, about.php and contact.php file (in my theme folder) they don't link to it. I'm following the "WordPress 3: Creating and Editing Custom Themes with Chris Coyier" on Lynda.com and the example shows that whenever you make a file with the same name as your page, it takes that directly (which works at his tutorial).
Anyone that could know what is going on?
Example:
I got a file blog.php in my theme folder, and when I go to www.mydomain.com/blog the loaded file is the index.php file, instead of the blog.php file
There are two ways you can get this working using custom page templates.
Create a template for one specific page using the page slug or ID. In this case, change the name of the php files like this to match the name of the page you created in the UI: page-home.php, page-blog.php, page-about.php and page-contact.php
Much more flexible is to create a custom template that can be used on ANY page. Just add the template name to the top of the php file like so (inside the php block):
/*
Template Name: My Home Page Template
*/
Then edit the pages and select your custom template from the template dropdown menu (on the right hand side I think, if its visible).
Reference this page for more info: https://developer.wordpress.org/themes/template-files-section/page-template-files/
Found the solution to my (silly) problem.
Creating a page in your theme directory & adding the template comment at the top of your php file isn't enough. You need to go to the admin panel->pages->YOUR PAGE-> and check out the page attributes. There you can link the page to a certain template: http://d.pr/i/a0m0

How to put own HTML into Wordpress theme?

I installed a Wordpress theme, but I would need to put there my own HTML code.
So, I would suppose I'll go into: wp-content/themes/theme_name/header.php and on the needed place I inserted needed HTML code.
I did it, but it didn't affect the website - the newly put HTML elements are not seen in the website.
Do I disregard anything? Or is needed to set up something in the WP administration?
Or problem with cache?
Sorry, maybe a stupid queston, I am just playing with WP for the first time.
The pages of your blog are created from different theme "parts". header.php is one of them. it creates the header of the page. Usually, before most HTML is output. footer.php is used for the footer of the page.
If you want your HTML code to go in the homepage only, use index.php (which calls header.php and footer.php). If you want your code to show in a page, use page.php. If you want your code to show when viewing a post, use single.php. Hope this helps.
Look in your different pages if get_header() function is called correctly. It is this function that includes header.php.
Check also your "theme_name/inc" directory. Sometimes the header.php or footer.php can be placed in the main theme folder and in the inc. If that is the situation you need to make sure to be editing the right file (the one in /inc).
First you have to check in wp-admin which theme is actives in your site suppose there are three theme and twenty eleven is active and you were checking twenty twelve so maybe this reason your new html will not shown in front-end so please check your current theme and work according to that from this location you can check it your current theme go to wp-admin => appearance => themes

WordPress: don't show 404 when no posts exist

Currently there is a bug in WordPress if you have a Posts Page set under:
Settings->Reading->A Static Page->Posts Page
If there are posts, than the page (e.g. with a slug called news) displays the post, and uses index.php from the theme.
But, with this configuration, if there are no posts, then it calls the theme's 404 page. This is definitely a bug, and has been submitted (Ticket #10822). It should be letting index.php show whatever it wants upon !have_posts(), but right now the page doesn't seem to be called at all.
My question is: is there a workaround for this bug without modifying core wp files? I'd be open to a plugin, theme changes, a custom page template, htaccess changes, etc.
I just performed a test for it. It isn't actually serving a 404, it's using index.php but since no posts are found so it falls outside of the have_posts(). Are you sure it's not a plugin or theme causing your issue? I tested this with the default theme on a base install of WordPress.
Most theme files have as part of their WP loop a catch for no posts, i.e.:
<?php else : ?>
Sorry, but you are looking for something that isn't here.
<?php endif; ?>
That might be what you're seeing. You can use a custom page template without that text (leave the loop) for yoiur posts page. And try Reveal Template | coffee2code.com to find out what template file you're looking at.

Categories