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

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags