Articles of php

Creating login session via CURL

Using the following code I experienced some problems: Login works but every link in the dashboard I will click will follow into the 404 not found page. It seems that there won’t be a working session created? $username=”admin”; $password=”admin”; $url=””; $cookie=”cookie.txt”; $postdata = “log=”. $username .”&pwd=”. $password .”&wp-submit=Log%20In&redirect_to=”. $url .”wp-admin/&testcookie=1″; $ch = curl_init(); curl_setopt ($ch, […]

WordPress shows registration link for non logged users

I have a WordPress site and I want to add a registration link for visitors. So, I added a menu item called ‘REGISTER’ with the following link: The problem is that this link opens the registration form for both users and visitors and I want to show it only to visitors.

How do I hardcode a WordPress shortcode into my theme?

I am using WooTheme’s Canvas theme and would like to “hardcode” in the [post_comments] shortcode into my theme. [post_comments] displays a comment link with comment count (ie Comments 10) in my post. Right now I am inserting the [post_comments] shortcode into my theme’s meta “Meta Manager”; however, this is not ideal for me as I […]

Using is_page() in functions.php not working at all

Trying to run a custom script on a single page using is_page in functions.php not working at all. I have a function called load_gh_boards that would enquque a script, only on a certain page (79): function load_gh_boards() { if( is_page(79) ){ wp_register_script( ‘gh-jobs-board’, get_bloginfo( ‘template_directory’ ) . ‘/js/gh-jobs-board.js’, array(), ‘1.0’, true ); }} add_action(‘wp_enqueue_script’, ‘load_gh_boards’); […]

in_category() works in single.php but not in page.php?

I’m using in_category(array) inside The Loop to detect whether a post is categorised into the Discussion category (or has one of a couple of slugs). This works beautifully on single.php but doesn’t even seem to be evaluated when used inside page.php? FWIW, here’s my code: <?php if ( in_category( array( ‘Discussions’, ‘discussion’, ‘discussion-article’ ) )) […]

Is Auto Post recognition a WordPress feature? How to turn it off?

I noticed that if you go to, it redirects to a post. Is this a feature in WordPress that can be turned off, or is this done by some type of plugin or custom code?

WordPress override bloginfo variable

How would I override a bloginfo variable in wordpress? For example, I want to replace this: <?php bloginfo(‘stylesheet_directory’); ?> to return a custom URL like

Custom excerpt function re-factoring

This may be more of a php best practices question, but here goes… I am using a custom excerpt trim function: function new_wp_trim_excerpt($text) { // Fakes an excerpt if needed global $post; if ( ” == $text ) { $text = get_the_content(”); $text = apply_filters(‘the_content’, $text); $text = str_replace(‘]]>’, ‘]]&gt;’, $text); $text = strip_tags($text, ‘<p>’); […]

How do I implement a .diff changeset from locally?

I have a local copy of the latest version of wordpress that I set up using svn co There is a diff that I want to pull into my local fileset: Is this something that I can do with subversion? What commands do I need to use?

Where would I place `wp_footer();`?

I am currently working on the footer.php file. I am just wondering where I should place the wp_footer(); in relation to the <footer> elements. Which of the following would be correct? Method A: <footer> <h1>Title Text</h1> <p>Some text</p> <?php wp_footer(); ?> </footer> </body> </html> Method B <footer> <h1>Title Text</h1> <p>Some text</p> </footer> <?php wp_footer(); ?> […]