Hot answers tagged

56

If by 'blog page' you meant a static page set as posts page in the Reading Settings, then you could check it by doing this: if ( is_front_page() && is_home() ) { // Default homepage } elseif ( is_front_page() ) { // static homepage } elseif ( is_home() ) { // blog page } else { //everyting else } When you use is_home() and is_front_page(),...


24

You can use the following in your themes functions.php file: function is_blog () { return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag()) && 'post' == get_post_type(); } And then put this in the file you are checking: <?php if (is_blog()) { echo 'You are on a blog page'; } ?> You can use Hooks in ...


16

If by 'blog page' you meant a static page set as posts page in the Reading: global $wp_query; if ( isset( $wp_query ) && (bool) $wp_query->is_posts_page ) { //static blog page } PS. This solution also works on template_redirect action


15

In WordPress 4.2 the editor was removed on whichever page was assigned to show Latest Posts for whatever reason. The following function below ( original solution found here by crgeary ) will re-add the editor and remove the notification: You are currently editing the page that shows your latest posts. Here's some information on the hooks used: ...


9

You are using get_the_content() wrong, it can't take a ID, which is what get_option('page_for_posts') does return, and generally gets the content of the current post inside the loop, in which it has to be used. To get the actual content of that page you can do: $page_for_posts_id = get_option( 'page_for_posts' ); $page_for_posts_obj = get_post( $...


9

It's been a while, but I came across this topic while looking for a way to enable gutenberg editor on the Blog Page. Didn't find any clue in google, so I dived into wordpress code and found the solution. Here is the code: add_filter( 'replace_editor', 'enable_gutenberg_editor_for_blog_page', 10, 2 ); /** * Simulate non-empty content to enable Gutenberg ...


6

An AJAX request is a new request to the server, and it is a request to admin-ajax.php. That is not a single post page. Any logic that depends on is_single() or any other page level template tags like it, won't work. If your AJAX callback needs that sort of information you must pass it to that callback in your AJAX request-- something like: function ...


6

A reverse proxy could work, such as varnish or nginx. Using varnish as an example: backend blog { .host = "blog-server-ip"; } backend default { .host = "current-domain-ip"; } sub vcl_recv { if (req.rul ~ "^/blog/") { req.backend = blog; } }


6

The function get_the_time is only designed to work either in the main WordPress loop or a custom loop using WP_Query, so the way you are using it won't work correctly. The following is the right way to use it, using a custom WP_Query loop: <?php // Get years that have posts $years = $wpdb->get_results( "SELECT DISTINCT YEAR(post_date) AS year FROM $...


6

This is because you call get_header() which already require your theme header.php, in which the meta tags are defined. You should learn how to use get_header() in the Wordpress Codex To summarize: You must rename your wp-blog-header.php file to header-blog.php and place it in your wordpress theme directory. Then you can require it using this function : ...


5

index.php and archive.php might be the same but don't have to be the same. index.php will display your blog post archive and in the absence of archive.php (or other more specific archive files) it will display your date, author, etc. archives as well. But it doesn't have to. You can, if you want, display your archived differently that your main blog index. ...


4

The very broad answer for why this doesn't work is that the internet is stateless. Basically each request for a page is a separate and unique instance from other page requests. Example Let's say post-1 is in category-1 and category-2. When Wordpress loads post-1 on single.php it has no way of knowing how the user arrived at the page. It only knows that ...


4

There are a couple of things I don't understand here, but I'll try answering them as I go along. You have a home.php, which I assume is your default homepage. You have one line of code in there, and that is to call a another page template. Here is you code <?php require dirname( __FILE__ ) . '/blog-page.php'; In blog-page.php you have the complete ...


4

You have custom filter in a plugin or in your theme that is messing with WP_Query. Your issue is that something is setting is_home to false. This is not default behavior, by default, is_home should return true in any custom instance of WP_Query. is_home is one of the contributing factors which is responsible for setting up sticky posts at the top in a ...


4

I'm pretty sure that is_singular() is going to return false when you are inside the WP loop, since there are more than one posts being looped through. Try is_single() or just look at the post object and examine the post_type attribute. add_filter( 'the_content', '_some_func', 15 ); function _some_func( $content ) { if( __check_paragraph_count_blog( $...


4

For anyone wondering, as custom excerpts don't get trimmed by the excerpt_length filter hook, try adding this filter: function trim_custom_excerpt($excerpt) { if (has_excerpt()) { $excerpt = wp_trim_words(get_the_excerpt(), apply_filters("excerpt_length", 55)); } return $excerpt; } add_filter("the_excerpt", "trim_custom_excerpt", 999);


3

The is_active_sidebar('Test'); function works correctly if the correct slug is used. I think that the problem is that you are constructing the sidebar ID like this: $sidebarID = preg_replace("/[\s_]/", "-", strtolower($page->post_title)); Then prepending sidebar- to it ... register_sidebar(array( 'name' => $page->...


3

There are Conditional Tags for this: is_archive() and is_category() respectively. For a custom post type archives you could use is_post_type_archive(). There are many conditional tags available, see above linked codex page. To determine the blog archive you have to additionally check for the post type post, take a look at this question and the answers for ...


3

The posts page will always be index.php or home.php. That is, WordPress will always use one of those files to display your blog posts. Even if you set some other page in Settings (like 'blog'), WP will ignore everything set for that page except the title. See the codex.


3

To get the blog index page, I found that if ( !is_front_page() && is_home() ) { // blog page } is not working for me, I had to use the get_option('page_for_posts') function to identify the Blog Page post_id, my answer is if ( !is_front_page() && is_home() ){ if ( empty ( $post_id) ) { global $post; $post_id = ...


3

WordPress 5.7 introduces a new helper function to more easily fetch the parent post's ID: get_post_parent() This can also be used in conjunction with has_post_parent(), so you could have something like looks like: <?php if ( has_post_parent() ) : ?> <a href="<?php the_permalink( get_post_parent() ); ?>"> <?php ...


3

When you make a page the page for posts, it's no longer a "page" in the conventional sense. Refer to the Template Hierarchy for home page display- the quickest fix is to rename your blog template home.php, and WordPress will load that before index.php.


3

A better way to to do this is to instead of a subdirectory, use a subdomain like blog.website.com. The reason for this is that a DNS record can be made to the other server for the subdomain, which is not possible with subdirectories. A subdirectory is possible, but you would have to use frames, a .htaccess redirect or another way which is totally not stable ...


3

The first option (/blog/) is the easiest: create a new blank page called "Blog" navigate to "Settings > Reading" and choose this new page as the value in the "Posts Page" drop-down Now, when you navigate to the new "Blog" page (which should be at /blog/ unless there is something unusual about your setup), all Posts are displayed, the most recent first.


3

First things first, avoid defining functions inside functions. PHP doesn't have a problem with it, but it's usually a sign you're "doing it wrong" and it just leads to unnecessary headaches. Second, your foreach loop at the bottom is a little malformed. You need to define the <ul> outside the loop, and then append to $html - otherwise you just end up ...


3

The standard query for posts uses orderby => 'post_date' and order => 'DESC'. The best candidate for arbitrary sort of posts would be orderby => 'menu_order' and order => 'ASC'. The menu_order is not generally used for posts but it is safe to be used. As suggested by Pieter Goosen use action hook pre_get_posts: add_action( 'pre_get_posts', '...


3

There is no conditional tag for the blog page. You have to use both is_home() and is_front_page() to detect this page When you use is_home() and is_front_page(), you have to use them in the right order to avoid bugs and to test every user configuration: <?php if ( is_front_page() && is_home() ) { // blog listings } elseif ( is_front_page() ) { /...


3

In my particular case functions.php of my theme was involved. Just remove empty space after end of "<?php /*code or comment*/ ?> " There should be NO empty space between "<?php ?>" tags. You can find more info: https://wordpress.org/support/topic/basic-image-editor-not-working/ Good luck!


3

There are two possible settings for this in WordPress. Option A Your front page (http://twistedtalesoftimmy.com/) is dynamic and shows the latest blog posts. Option B Your front page (http://twistedtalesoftimmy.com/) is static and points to a regular page in WordPress. There is another page (e.g. http://twistedtalesoftimmy.com/blog/) that shows the ...


3

I know this is an old question but I was having the same issue in a theme I inherited and came across this question in my search for answers. In my particular case, I found the following PHP code included in the theme's function.php file: if( is_category() || is_date() || is_author() ) { global $wp_query; $wp_query->set_404(); //set to 404 not ...


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