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

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.