How to load scripts without the get_header() function - php

I'm looking for a way to scripts that a plugin need to run without the get_header(); function
here's a backstory about what's happening
I'm working on BuddyPress plugin, specifically the template part of it.
I created new template, define the file and everything is running without errors.
The template I'm working on doesn't use the get_header(); function because I don't want the header in that template to be visible.
A picture of how's the code looks like:
/*
* This Is A BuddyPress Template [ With No Header ]
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
<?php
/**
* generate_before_main_content hook.
*
* #since 0.1
*/
do_action( 'generate_before_main_content' );
if ( generate_has_default_loop() ) {
while ( have_posts() ) :
the_post();
generate_do_template_part( 'page' );
endwhile;
}
get_footer();
Everything is good to this point: BuddyPress loads and the profile user loads.
The issue is that the members page stucks at Loading members of the community. Please wait. and every non static page is stuck.
Well this is happing because some scripts are not loading in <head> </head>
but when I call the get_header(); function
all the scripts load
I tried to search about it in Stackoverflow but haven't found anything I needed and some scripts are not working and it's undefined
like the wp_print_head_scripts(); - it not printing any scripts and this method didn't work
I also tired to load it directly from the same template like
and that didn't work ether
So I'm stuck here. Anybody? if I forgot something please tell me I'll appreciate that (:

sorry , i totally forgot about the wp_head():
wp_head() loads all the scripts needed without the header

Related

replaceing default header/footer with custom template part in wordpress

the code below is part of main php code for Dokan Vendor Shop Page.
in Full Site Editing i have added my custom header / footer (name in template part: My Custom Header) and using replace optioni was able to show them instead of default header/footer in all other template but i am unble to replace/show them in this custom php code.
i have tried get_header( 'my_custom_header' ); and php get_footer( 'my_custom_footer' ); and no luck.
please help me how to achieve that?
<?php
/**
* The Template for displaying all single posts.
* #package dokan - 2014 1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header( 'shop' );
?>
<?php do_action( 'woocommerce_before_main_content' ); ?>
<div class="dokan-store-wrap
....
....
</div><!-- .dokan-store-wrap -->
<?php do_action( 'woocommerce_after_main_content' ); ?>
<?php get_footer( 'shop' ); ?>
The problem is that you are mixing two meanings of template. get_header() is function (and the same get_footer()) which will "paste" the code of a php file. So your theme has a *.php template (in your case it will be named header-shop.php) and by calling get_header() it will add header in process of rendering the website.
On the other hand, you created your header/footer templates in Gutenberg editor. They are handled by a Gutenberg plugin. You should just try call get_header(); without any parameters. It should be handled in the standard way and then you can modify it using Full Site Editing.
Before that, you should check if on your specific page there isn't a function get_header() override. It can be done by some plugin.

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.

wordpress theme breaks after inserting external php ? possible mistake in folder config?

I am new to wordpress and following is my scenario.
I am inserting an external php script in wordpress by creating a new template in the theme and then using that template in a new page.
When I do this the new content is visible in the loaded page (and works as expected) but the theme breaks for the page i.e. all side bars (right and bottom) get lost. and if i am logged in the wpadmin bar at top is lost for that page only.
for all other pages everything comes back.
Could you guys please help me what could be going wrong here.
I doubt that there is some folder config going wrong somewhere.
Following is what I am doing:
inside my new theme page template -
<?php
/**
* The template for displaying pages
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages and that
* other "pages" on your WordPress site will use a different template.
*
* Template Name: abctemplate
* #package WordPress
* #subpackage Twenty_Sixteen
* #since Twenty Sixteen 1.0
*/
?>
<?php
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
include_once dirname(ABSPATH) . '\abc\index.php'; // <=== the EXTERNAL SCRIPT
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
comments_template();
}
// End of the loop.
endwhile;
echo "end post loop";
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php echo "get_sidebar"; get_sidebar(); ?>
<?php echo "get_footer"; get_footer(); ?>
The above script internally after setting some variables, calls following template:
require_once('templates/'.$template.'/index.php');
the above template is a simple html page calling some variables in above abc/index.php
calling this breaks the wordpress theme mostly, the sidebars, (i am not sure yet if it breaks something else).
Could this mean that wordpress did not find the required side bar related files? but everything is inside the theme template.
Basically this whole thing is a scenario of loading an existing webpage into wordpress. I have the functionality working but UI breaks.
The problem I see first is naming the templates.
you have the following, which will throw a PHP parse error:
<?php
Template Name: abctemplate
?>
Have a look at the documentation here: https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/
A template name should be in a docblock as follows
<?php
/**
* Template Name: Full Width Page
*
* #package WordPress
* #subpackage Twenty_Fourteen
* #since Twenty Fourteen 1.0
*/
Guess what ! it was the die() which was breaking everything. And the way I found it was totally lame(removing approx 2000 lines of code one by one). Anyways the reason makes a bit sense to me now. Thanks!

Wordpress - Twenty Fourteen Theme - Moving Featured Content Slider to Content Area

I am using the featured content slider provided as standard in the Twenty Fourteen Wordpress theme. It's doing pretty much everything I want it to do at this point and I have done some basic customisation on it using CSS, however after speaking to a few folk internally they are looking to "insert" this into the main content area of the page.
I've had a look around, and found a suggestion to change the index.php file to change the position of the PHP statement that registers the featured content. After making these changes to my child theme and publishing them nothing happened.
I am at a complete loss as to where to look next or what to change (without trial and error which could break everything!)
It's probably a very simple solution that I'm completely overlooking so apologies if this is the case. This is an internal site so I can't provide any links unfortunately. Many thanks in advance for your help!
Index.php current code:
get_header(); ?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
if ( have_posts() ) :
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
<?php
if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
// Include the featured content template.
get_template_part( 'featured-content' );
}
?>
Further to this, the Featured Content is currently located at the top of the page and does not fit within the content and primary sidebars (it is positioned above the content sidebar to the right of the primary sidebar.
If you're worried about breaking a live site, then you should make a copy of what you've got, and install it locally on your machine.
WAMP is very good for this, if you're running Windows, and makes your computer act like an Apache web server.
Moving on from that, it would be helpful if you could provide some code, showing where your featured content slider is positioned.
And also make sure you're editing the correct file for your theme.

Inserting custom content block into wordpress

I've been looking around for a while on how to do this but I don't think I've been wording my searches correctly. I'm developing a custom theme and want to break out a section of a page into a reusable piece that I can reference like you would insert a header with <?php get_header(); ?> but I want to use a different header file instead of header.php. How would I do this?
You can use the function like this:
<?php get_header( $name ); ?>
$name :: (string) (optional) Calls for header-name.php.
if you have a seperate header for home page you can create a header file like this "header-home.php" to call that header file use the get_header function like this:
<?php get_header( 'home' ); ?>
Also you can call multipe header in a theme like this according to different conditions
<?php
if ( is_home() ) :
get_header( 'home' );
elseif ( is_404() ) :
get_header( '404' );
else :
get_header();
endif;
?>
You can specify which header file you want to use by naming it, as Ajith R Nair said in his answer. <?php get_header('new');?> would load the file header-new.php in your theme's directory. If you plan on changing small parts of your header, I suggest not using duplicate header files, but instead define a global variable that holds an array of default parameters in the header file, and just use that same global variable in your theme pages to override defaults. Hopefully that points you in the right direction, though I would be happy to clarify if needed.

Categories