• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2665

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

Show Shortcode Content Before Posts On Home Page Only

Here’s a fairly common question i see asked on many WordPress related forums:

I’ve got a next gen gallery showing above the first post on the home page. I want to keep it there, but not have it show up on any other page or single blog posts.

I’ve put it in the ‘before loop’ section on simple hooks. How can I get it to only show up on the home page?

My Answer

Rather than use the Genesis simple hooks plugin, you can add the hook to a custom function and put the code in your child themes functions file like this:

The only problem with the above code is it will also display on all paginated pages if the front or home page includes a loop.

To fix this, you can modify the code so it only displays on the first page of the front or home page.

There’s also other ways to code the if statements with conditional tags and query variables so your content only displays before your posts on the first page of your sites front page.

The above code only executes your shortcode on the first page of your home page and not paginated pages.

Related Posts

  • Add Widget Before Loop On First Page Of Front Page or Posts Page

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems