Articles of functions

Include a php file from functions.php only to homepage

I’m re-developing a wordpress theme using sage them framework. I have this array in functions.php $sage_includes = [ ‘lib/assets.php’, // Scripts and stylesheets ‘lib/theme_options.php’, // Theme Options ‘lib/setup.php’, // Theme setup ‘lib/titles.php’, // Page titles ‘lib/wrapper.php’, // Theme wrapper class ‘lib/home_shortcodes.php’, // Homeapage Shortcodes ‘lib/shortcodes.php’ // Old Theme Shortcodes ]; which is loaded below foreach […]

Is there a wordpress function that I can use to retrieve the current page that is loaded?

Suppose that I create a page in the admin section (under ‘Pages’) and I have permalinks turned on and this pages slug is ‘my-new-page’, then is there a WordPress function that will work outside the (blog) Loop that I can use in that page’s template on my theme that will retrieve that page’s permalink?

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? […]