Articles of php

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 lostlettermen.com/aa, 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 http://mysites.com/hello/

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 core.trac.wordpress.org locally?

I have a local copy of the latest version of wordpress that I set up using svn co http://core.svn.wordpress.org/trunk/ There is a diff that I want to pull into my local fileset: http://core.trac.wordpress.org/attachment/ticket/19371/19371.diff 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(); ?> […]

If search results empty then execute certain code

If search results are empty then I want that some code be executed, but how to write such situations programmatically? If !is_search() { certain code } But above doesn’t work.

Using $_GET in Functions.php

I keep getting an undefined index error with this code in functions. What am I doing wrong? function hire_more(){ $hire = $_GET[‘hire_more’]; write_log($hire); } add_action(‘wp_loaded’,’hire_more’);

Colorbox ajax loading of outside HTML content works perfect on localhost but not on server

I am trying to render content generated by a php file in [jQuery Colorbox][1] through AJAX in my WordPress site. The PHP resides on the same server in the same domain. It works perfect when I run it on localhost but it’s not working on the server. Here is the link to my site – […]