91

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.


13

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( '...


13

WordPress body_class($class) is a nice dynamic way to load styles, js for specific body contents. If your theme doesn't support body class add them very simply: Open the header.php (or the template that contains the <body> tag) Edit the <body> tag and make it to <body <?php body_class(); ?>> — you are Done! :) Now when you are ...


13

$pageID = get_option('page_on_front'); should get you the Page ID of the page set at 'Front Page' in WordPress options.


11

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. ...


11

You should be able to use $front_page_id = get_option( 'page_on_front' ); It'll return the ID of the page you're using as your site's front page, or 0 if it hasn't been set. Codex: get_option()


8

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 ...


8

You are using a theme or plugin that uses a jQuery-dependent script with poor syntax. In this screenshot below of the browser console of the page you referenced, the expression should be ... li > a[href*='#']. Note the missing quotes around the #. The bug didn't show up until now because WordPress 4.5 updated the version of jQuery it uses. The new jQuery ...


8

You have the WordPress function is_front_page() that you need to invert with "!" . if(!is_front_page() && in_category( array(10,11,12,13,14,15,18,19,20) ))


7

I had faced the same problem. And finally, I solved the problem. Getting the current Pagination Number <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?> For getting the current pagination number on a static front page (Page template) you have to use the 'page' query variable. <?php $paged = (get_query_var('page')) ? ...


7

The posts_request filter Skimming through the WP_Query we find this part of interest: if ( !$q['suppress_filters'] ) { /** * Filter the completed SQL query before sending. * * @since 2.0.0 * * @param array $request The complete SQL query. * @param WP_Query &$this The WP_Query instance (passed by reference). */...


6

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()) : ?>...


6

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. Here ...


6

Strange. Outside the loop, the_title() should give you the current page name, if you really are on a page, and not viewing a specific post. If it gives post title instead, it may mean that you are somehow inside a loop. But if that were true, wp_title shouldn't show "Blog". See if other options give the same result: //the_title(); single_post_title(); echo ...


6

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 ...


6

If by Home Page you mean the page designated as the Posts page, the ID is stored in the option page_for_posts. If the value is 0, there is no designated home page.


6

Several options: Out-of-the-box plugin If you're using Yoast WordPress SEO, you have a built-in setting for Facebook images. Under your SEO > Social menu, go to the Facebook tab and select an image under "Frontpage settings." You can also set an image as a fallback, for posts that have no featured image, under "Default settings." Other SEO plugins may ...


6

I strongly advise you to heed the advice already given. If your PHP is well structured and you take advantage of caching methods, it won't have a significant increase on your page load time. We've got pages with extremely complex queries that are hardly optimized, but using some clever caching methods, we're able to get those pages served in 500-900ms, or 2-...


5

I know this question was answered years ago, but for those looking for a solution that find this page, there is a MUCH easier solution. Go to Posts > Categories and click on Quickedit for the default blog category called Uncategorized. Rename Uncategorized to Blog and change the slug to blog. Then, when you create new categories, select Blog as the parent ...


5

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


5

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 marigolds-...


5

If the goal is such: I do not want to show the date/time on the front page to keep the layout cleaner, only on the other pages that this loop is displayed on. Then you should be able to use a simple conditional: <?php if ( ! is_front_page() ) { ?> <p><?php the_time('F Y'); ?></p> <?php } ?> Without knowing exactly what ...


5

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 ...


5

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() && $...


5

You can make use the queried object to return the title of the page used as blogpage You can use the following: (Require PHP 5.4+) $title = get_queried_object()->post_title; var_dump( $title );


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 ...


4

This should work for you if you put it in your themes functions.php file, but you may want to modify the conditions, and the url to redirect to depending on your set up. function loginRedirect( $redirect_to, $request, $user ){ if( is_array( $user->roles ) ) { // check if user has a role return "/wp-admin/edit.php?post_type=page"; } } ...


4

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 ', ...


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

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( '...


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