Site logo

Archived topic

Custom wp_head for custom pages, e.g. front-page.php

3 replies · Started by Matthew on August 29, 2019

Viewing posts 1–4 of 4

Hey Tom et al.,

Recently began using GP on all of my client's sites and so far every script/style issue encountered has been solved by this forum and your extensive documentation -- thank you -- except for this one....

Trying to remove the standard <head> on selected pages to create streamlined landing pages with minimal size, scripts and requests. Custom templates do not work because get_header() pulls both <head> and <header> -- neither does calling a header custom $name like this: if ( is_front_page() ) : get_header( 'home' ); else : get_header(); endif;

So I created front-page.php and a custom stylesheet to accompany it, however that does not work either.

if ( ! defined( 'ABSPATH' ) ) {exit;}
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
	<meta charset="<?php bloginfo( 'charset' ); ?>">
	<link rel="profile" href="https://gmpg.org/xfn/11">
	<link type="text/css" media="all" href="style-front.css" rel="stylesheet" />
</head>
<body class="fp" itemtype="https://schema.org/WebPage" itemscope>
	<?php
	do_action( 'wp_body_open' );
	do_action( 'generate_before_header' );
	do_action( 'generate_header' );
  ...etc...

Even using Cloudflare, AutoOptimize, and every speed trick in the book, GP front pages are around 2X slower and 50% larger than the same content displayed via front-page.php -- active plugins include their css/js in the head even if they are not being used on that page.

To summarize, I want to continue migrating all of my clients from Genesis to GP but first I must find a way to preserve their home page and landing page speeds. Any suggestions on how to do this would be greatly appreciated, thanks!

Oh and yes, I have already spent several hours reading countless forum posts, including the following:
https://generatepress.com/forums/topic/how-to-create-custom-page-template-for-blog/
https://generatepress.com/forums/topic/remove-css-from-html/
https://generatepress.com/forums/topic/custom-css-classes-and-generate_do_element_classes/

Hi there,

Are you just trying to remove everything from the wp_head hook?

If so, I wonder if this would work?:

add_action( 'wp', function() {
    if ( is_front_page() ) {
        remove_all_actions( 'wp_head' )
    }
} );

Let me know :)

Yup, Tom, that worked perfectly -- thank you!

No problem :)

This archived topic is closed to new replies.