Tag Info

Hot answers tagged

18

is_front_page() returns true if the user is on the page or page of posts that is set to the front page on Settings->Reading->Front page displays So if you set about us as the front page then this conditional will only be true if showing the about us page. is_home() return true when on the posts list page, This is usually the page that shows the ...


9

There are many solutions to this problem. And every one of them is correct, I guess. It depends on what you really want and what will be most friendly/clear to user/administrator of this page. I usually use 3 ways to solve this. Which one of them I chose? It depends on situation. Sometimes I use 2 of them simultaneously. 1. Static front page solution. ...


8

Hi @Alkaline: I think you are looking for this: // $page is a post where post_type=='page' if (get_option('show_on_front')=='page') { $page_id = get_option('page_for_posts'); $page = get_post($page_id); } else { $page = false; }


7

Let's see if I can confuse myself. If either of your two OR conditions is true the code executes. is_home and is_front_page can return true for different pages, negated in your case. If you have a static from page, which it sounds like you do, then is_home is the blog index page. Note: WordPress 2.1 handles this function differently than prior ...


7

Update Eliminating all of the other solutions, there is at least one remaining: template_redirect: function wpse121308_redirect_homepage() { // Check for blog posts index // NOT site front page, // which would be is_front_page() if ( is_home() ) { wp_redirect( get_category_link( $id ) ); exit(); } } add_action( ...


6

You don't want a post to be the front page, you want a custom post type entry to be the front page. Now that we have the terminology right, yes it's possible. A client once asked me to do the exact same thing. They had a custom post type they needed displayed on the front page. Doing so was as simple as adding a filter to allow them to select a "stack" ...


6

Maybe so? Refined version of my earlier solution. add_filter( 'wp_dropdown_pages', 'add_cpt_to_front_page_dropdown', 10, 1 ); /** * Adds CPTs to the list of available pages for a static front page. * * @param string $select Existing select list. * @return string */ function add_cpt_to_front_page_dropdown( $select ) { if ( FALSE === strpos( ...


6

If you are using the default home page, which in most cases is a list of most recent posts, is_home() should work. If you have set a static page to be your front page (in Settings >> Reading), is_front_page() should work. If you are not getting the results you expect using this: if (is_front_page()) { //the code you want to execute } perhaps you can ...


6

When the installer runs it calls wp_install(), that in turn calls populate_options() defined in wp-admin/includes/schema.php, which runs the following.. if ( !__get_option('home') ) update_option('home', $guessurl); Prior to that $guessurl is defined by.. $guessurl = wp_guess_url(); The guess URL function is defined in wp-includes/functions.php and ...


5

This is really not enough information, so I have to guess. A) The div is part of the content Use PHP, check for front-page, and if not, handle the div: <?php if (! is_front_page()) : ?> <div /> <?php endif; ?> B) The div is located somewhere else on the page Give the div an ID and use jQuery: <?php if (! is_front_page()) : ...


5

I solved it using the offset query parameter. This allowed me to edit the query in the pre_get_posts hook, and seems to be the cleanest way to do this, without a new query. Now the home page shows only one post, and page/2/ shows posts 2-11. All links keep working, no other modification is required. add_action('pre_get_posts', 'set_offset_on_front_page'); ...


5

First, if you want to target the site Front Page, you need to use is_front_page(). The is_home() conditional returns true when the blog posts index is displayed, which may or may not be on the site Front Page. Second, you need to hook your function into an appropriate hook, which it appears in this case is wp_enqueue_scripts. (Also: what is ...


5

Thanks to @toscho for the useful answer, but it felt a bit hackish to me, so I poked around a bit and figured out I could add a filter instead: function wpa18013_add_pages_to_dropdown( $pages, $r ){ if('page_on_front' == $r['name']){ $args = array( 'post_type' => 'stack' ); $stacks = get_posts($args); ...


5

I think you can set your post to private to view it privately on the homepage. Once you change the visibility to private, the post or page status changes to "Privately Published" as shown. Private posts are automatically published but not visible to anyone but those with the appropriate permission levels (Editor or Administrator). See here. ...


5

You can use the wp_loaded hook to push all non-logged-in traffic to the login screen. Note how I've passed $_SERVER['REQUEST_URI'] to wp_login_url() - this is passed as a URL parameter to the login page, and once a user successfully signs in, they'll be redirected back to the URL they were originally trying to visit. function ...


4

WordPress has a few useful options, you can get the homepage ID by using the following: $frontpage_ID = get_option('page_on_front'); or the Blog ID by using: $blog_ID = get_option('page_for_posts'); Here's a list of many useful get_option parameters.


4

You should use pre_get_posts to alter the main query on the home page. With the proper conditional tags and parameters (check WP_Query for available parameters) you can achieve what you need You can do the following to just display posts from a given tag on your homepage add_action( 'pre_get_posts', function ( $query ) { if ( !is_admin() && ...


4

You're calling it on the wrong hook, and you're calling the wrong conditional function to test. When the after_setup_theme hook is fired, WordPress hasn't finished processing wether you're on a page or a homepage yet. You should also never pass in hardcoded post IDs. In this case is_home works, as might is_front_page. If you really must reference a ...


4

I'd suggest creating a metabox for the home.php page template. This is easily done with the Advanced Custom Fields (ACF) plugin. You can even use "ACF Lite" if you'd like to build these into your theme, instead of using the plugin. Here's quick and easy way to implement exactly what you're looking for. Create A Custom Metabox that only shows up on the ...


4

Why not just create a front-page.php template file, that uses either a normal query/Loop, or (if a custom Theme option is set to display the CPT on the Front Page), outputs a custom query/Loop, based on the CPT? The issue there is that you would have to create a separate Theme option to control the Front Page output, while at the same time instructing users ...


4

To be able to use the comments template in your loops, add global $withcomments; $withcomments = true;


4

If I remember right (template hierarchy gets messy in these parts) when you assign page to be posts page then its template is ignored in favor of home page template branch. So try editing home.php (if you have it) or index.php.


4

<div id="posts"> <?php // define query arguments $args = array( 'posts_per_page' => 8, // your 'x' goes here 'nopaging' = true // possibly more arguments here ); // set up new query $tyler_query = new WP_Query( $args ); // loop through found posts while ( $tyler_query->have_posts() ) : ...


4

Before I address your main issue, I must point out a glaring syntax error: <?php if( !is_home() || !is_front_page() ) { ?> <p><?php the_time('F Y'); ?></p> <?php endif } ?> Why is the endif there? It makes no sense whatsoever, and everything in programming has a purpose/reason. You might as well change it to ...


4

The modern way would be to use html5 which does support geolocation: simple demo A bit longer explanation how this could be added to a web-app here A nice php script that uses a web service called geoplugin (the api is nice, no idea about the company, ymmv!) And last but not least, using the html5 geolocation from php (which you would need for wordpress) at ...


3

Create a file front-page.php with the following content: locate_template( 'category-image-gallery.php', TRUE, TRUE ); That’s all. For the theme’s functions.php If you want to restrict the front page content to posts from that category, filter the front page query: add_action( 'pre_get_posts', 'wpse_74225_frontpage_categories' ); function ...


3

Try it: <?php $class = ! is_home() ? "interior" : ""; body_class( $class ); ?> Or this: <?php body_class( ! is_home() ? "interior" : "" ); ?>


3

Register a widget, and call it on the front-page when the the_post action is called second time: add_action( 'wp_loaded', 'wpse_80202_register_banner_widget' ); function wpse_80202_register_banner_widget() { // used on the first page of main loop only register_sidebar( array ( 'name' => 'Banner front-page ', ...


3

You can use the function is_front_page(). Put this where you want to check if is frontpage if( is_front_page() ) { echo 'I am the frontpage'; } It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page displays is set to "Your latest posts", or when is set to "A static page"



Only top voted, non community-wiki answers of a minimum length are eligible