Widgets in the loop if active

Think about what is happening. You run the_post(); which sets $post to the first post in the Loop, but you don’t use that post if your sidebar is active. Then the Loop continues and $post gets set to the second post in the Loop. You’ve lost your first post. I don’t see why that first … Read more

WordPress page content outside WordPress

The alternative way. Problem with @david.binda solution is that: you have to hardcoding a lot of things, (manually write db credientials, table prefix..) You cannot use content filter (so if you have shortcode in your page, you will see some [something] instead of desired content..) sure you can load wordpress environment, but… Just yesterday I … Read more

Get author and excerpt from URL

There is a function called url_to_postid $id = url_to_postid( get_permalink(40) ); // $id will be 40 Actually (WP 3.6) it works only for standard posts and page, but with WP 3.7 it will also work for custom post types.

wp_dropdown_pages auto submit

You can use the following piece of code. <form action=”<?php bloginfo(‘url’); ?>” method=”get”> <?php $select = wp_dropdown_pages( array( ‘post_type’ => ‘ce_artists’, ‘show_option_none’ => ‘Select Artist’, ‘echo’ => 0 ) ); echo str_replace(‘<select ‘, ‘<select onchange=”this.form.submit()” ‘, $select); ?> </form> You can find a similar example here in the codex

WordPress displaying content from sub pages

It sounds like you may be looking for wp_list_pages(): $args = array( ‘child_of’ => $post->ID ); wp_list_pages( $args ); With the appropriate arguments I am almost certain that you can do what you need with that function.

Display post category in foreach loop

When the foreach loop is from get_posts(), you need to run setup_postdata() for each post if you want to use themplate tags inside the loop like the_category(), if not you can get unexpected behaviour. Also, you will need to run wp_reset_postdata() after the foreach loop. Note that the_category and similar template tags actually displays/echoes the … Read more

I restricted wordpress by logged users. It’s possible exclude a page?

I wanted to restrict my website except a specific page. This is my solution: function restrict_access_if_logged_out(){ global $wp; if (!is_user_logged_in() && !is_home() && ($wp->query_vars[‘pagename’] != ‘name-of-page’) ){ $redirect = home_url() . ‘/wp-login.php?redirect_to=’ . esc_url($_SERVER[“HTTP_HOST”] . urlencode($_SERVER[“REQUEST_URI”])); wp_redirect( $redirect ); exit; } } Only I added this: && ($wp->query_vars[‘pagename’] != ‘name-of-page’) in IF clause and a … Read more

is there a benefit in using a constant over get_stylesheet_directory_uri?

You can read up the source code of theme.php where get_stylesheet_directory_uri() is defined, inside you’ll see a str_replace() wich is consuming additional resources on each request. The best way to avoid this is to define a variable or constant that contains the path. In that case it is only called once. https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/theme.php#L0

Adding logo to WordPress header

It says right there in the code: <?php // to use a image just replace the bloginfo(‘name’) with your img src and remove the surrounding <p> ?> So just replace this line below that comment: <p id=”logo” class=”h1″ itemscope itemtype=”http://schema.org/Organization”><a href=”https://wordpress.stackexchange.com/questions/227227/<?php echo home_url(); ?>” rel=”nofollow”><?php bloginfo(”); ?></a></p> with this: <p id=”logo” class=”h1″ itemscope itemtype=”http://schema.org/Organization”><a href=”https://wordpress.stackexchange.com/questions/227227/<?php … Read more