Articles of functions

Best way of adding CSS which can be manipulated by the user via theme option panels?

I thought about adding it as inline CSS with code from the functions.php (not really sure how to do it). Something like this: function addcss() { background: $this_is_the_css_value; } I would like to know that. But if there’s is a better option (without adding inline CSS). I would like to know it too.

wrong php date()?

hey guys, it’s weird and I’ve never experienced that before. I’ve created a new blog and a custom theme. I’m using <?php echo date(“H:i”); ?>in my theme. The time that’s put is 2h earlier. e.g. if it’s actually 16:00 o’clock the date generated with date() is 14:00. I don’t know why that happens? I’m using […]

wp_insert_posts keeps adding multiple pages

I have a function that creates a page but I only want one page and the code below keeps adding multiple pages (2 at a time). Is there a way to only add one post? I tired this solution but it didn’t work. $my_post = array( ‘post_title’ => ‘My page Reql’, ‘post_type’ => ‘page’, ‘post_name’ […]

Using Default WordPress Custom Header Image Crop Feature in a Post Type / MetaBox

I am not sure how many of you have experimented with the new custom header image functionality of wordpress 3.0 but its actually very cool (enabled by adding the function to your functions.php file). One of the key things which I find to be extremely useful is that it allows you to upload an image […]

Remove the deleted users avatar from list

Problem Hi everyone, I have a bit of a problem. I have a function that outputs the avatars of users that follow me . It works great, but if the user is deleted the avatars remain visible as a blank image box with a broken hyperlink missing the users username. Is there any way to […]

Twenty Eleven Child theme error when attempting to use a rewritten function

I attempted to make a minor change to a function in the Twenty Eleven theme (wordpress 3.4.2) I get this error message: Fatal error: Cannot redeclare twentyeleven_widgets_init() (previously declared in /home/labfocus/public_html/wp-content/themes/twentyeleven-child/functions.php:10) in /home/labfocus/public_html/wp-content/themes/twentyeleven/functions.php on line 438 Here is the function that I am attempting to add in place of the original <?php if ( !function_exists(‘twentyeleven_widgets_init’)) […]

if && problems with transition_post_status

I’m attempting to get this function to work and it seems to not work when put together. When I just have $new_status == ‘publish’ it works, when I use just the second it also works. When I attempt to && them together there seems to be a hiccup. Also it should be noted that I […]

Stripping shortcode from custom excerpt function

I’m using the following function to create a custom excerpt for my homepage and categories pages so I can do it by character count and have a custom “read more”. However, I have captions shortcode showing up in my excerpt. Example: Do you sometimes feel overwhelmed when trying to decide what to make for dinner? […]

is_user_logged_in not working to redirect only logged out users

So I have the code below in my functions.php file. It works for logged out users but it also redirects users that are logged in. Can anyone help? add_action( ‘template_redirect’, ‘redirect_to_specific_page’ ); function redirect_to_specific_page() { if ( is_paged() || is_author() || is_single() && ! is_user_logged_in() ) { wp_redirect( ‘’, 301 ); exit; } } I’m […]

Template tags vs get_template_part() vs functions.php

When to use template tags and when to use get_template_part() and when to use function.php? I am confused at them. For example, if I want to show related portfolios under single portfolio, I can create a template tag named show_related_portfolios(). In contrast, I can create a file named content-related-portfolios.php, and use it like get_template_part( ‘content’, […]