background preloader

WordPress without plugins

Facebook Twitter

GenerateWP - User friendly tools for WordPress developers.

Menus and misc code

How To Make Sticky Posts Even Stickier In WordPress | Interconnect IT - WordPress Consultants, Web Development and Web Design. <? Php * Fixes sticky post ordering in WordPress anywhere the order is not explicitly defined. * Updates a post's menu order whenever the sticky posts option is updated * Props to Simon Fransson of for a bugfix where 'unstickied' posts were not updated * @param Array $stickies An array of post IDs * @return Array The original array passed in add_filter( 'pre_update_option_sticky_posts', 'fix_sticky_posts' ); function fix_sticky_posts( $stickies ) { $old_stickies = array_diff( get_option( 'sticky_posts' ), $stickies ); foreach( $stickies as $sticky ) wp_update_post( array( 'ID' => $sticky, 'menu_order' => -1 ) ); foreach( $old_stickies as $sticky ) wp_update_post( array( 'ID' => $sticky, 'menu_order' => 0 ) ); return $stickies; * Rewrites the query to sort by menu_order first and then date in standard lists - ignore if date archive and also ignore if the 'ignore_sticky_posts' flag is set add_action( 'pre_get_posts', 'sticky_posts_query' ); function sticky_posts_query( $q ) { if ( !

GenerateWP. WordPress Custom Post Type Code Generator. How To Show Youtube Video Outside The Post In WordPress. Embedding Youtube video in the post content in WordPress is extremely easy, just wrap it in the [ embed ]. Or even easier by checking the options Auto-embeds in Settings > Media and WordPress will automatically turns Youtube URL into the embedded video. But that’s for the post content. How do we embed the Youtube video in other places of WordPress blog, such as sidebar, footer, etc.? Especially when you add the Youtube URL to the post using custom meta field? The first idea shown in my mind is that apply the shortcode [ embed ], just like this: $video_url = get_post_meta( get_the_ID(), 'youtube', true );echo do_shortcode( "[ embed ]{$video_url}[ /embed ]" ); But it doesn’t work! So, to solve this problem, we need to use a function wp_oembed_get(): $video_url = get_post_meta( get_the_ID(), 'youtube', true );echo wp_oembed_get( $video_url, array( 'width' => 400 ) ); The 1st argument is the Youtube video URL, or even better, any supported oEmbed services.

Hope that’s helpful for you. Excluding your plugin or theme from update checks. There has been a vigorous discussion going on regarding what data WordPress installs send to WordPress.org when doing update checks. Because WordPress (the software) doesn’t know whether a theme or plugin is listed in the WordPress.org repositories, it has to check them all, and let the repository sort it out. Some have expressed concern that private plugins developed for a single client could contain sensitive information in their headers, like contact information for the developer, etc.

If you, as a plugin or theme developer, would like to exclude one of your plugins or themes from the update array, the following code will do the trick. For plugins: Just change the cws_hidden_plugin_12345 string (two instances) to a namespaced function name for your plugin, and you’re good to go. For themes: Put this in your theme’s functions.php Again, just change the cws_hidden_theme_12345 string (two instances) to a namespaced function name for your theme.

Like this: Like Loading... The Right Way to Use Google Web Fonts with WordPress. Impose a Maximum Limit on Image upload size. Uploads - How to Require a Minimum Image Dimension for Uploading. Code snippets — studiograsshopper. WordPress – List all image sizes in Media Uploader — studiograsshopper. I don’t know about you, but I have always found it frustrating that new image sizes added via the add_image_size() function do not get listed automatically in the Media Uploader after an image has been uploaded, so that one can easily insert one of these sizes into the post. Although there are some plugins out there which add this functionality, the WordPress core code hasn’t – until WordPress 3.3 (still in beta at time of writing) – made it easy to do so, either. However, thanks to the new image_size_names_choose filter added to the image_size_input_fields() function in wp-admin/includes/media.php, adding additional image sizes to the Media Uploader is now very easy.

This code works in WordPress 3.5+ but, of course, the WP 3.5 media uploader uses a dropdown select box instead of the radio buttons shown in the WP 3.3 screenshots below. Read on to find out how to go from this: To this: The code… Add this code to your theme’s functions.php file: Some info which may be useful… WordPress Function to change Background to Featured Image | Geek the Freak Out! It's Joseph Hinson! Expand the WordPress Media Library Admin Panel. As of WordPress 2.8, it appears that the only way to insert new interface panels into the WordPress Media Library is through the restrict_manage_posts action hook. Below I describe how I use this hook to expand the Media Library admin panel. 1. Media Library Menu Check Be careful when you use this hook because it gets called in other admin menus as well, including the Posts menu.

To limit my new menus to just the Media Library, I first do the following check in my plugin file or functions.php theme file. add_action('admin_init', 'init_media_plus'); function init_media_plus() { // Only activate plugin for the Media Library page if (strpos($_SERVER["REQUEST_URI"], "upload.php") === FALSE) return; add_action('restrict_manage_posts', 'media_library_menu'); add_action('admin_head', 'media_plus_header', 51); add_filter('wp_redirect', 'media_plus_redirect', 10, 2); } Line 5 – The Media Library menu is constructed from the wp-admin/upload.php file.

Line 9 – Add any Javascript functions here. 2. 3. 44 WordPress Media Library Hacks. WordPress has evolved from a blogging tool to a fully fledged content management system (CMS). It wouldn’t run 70+ million websites if it didn’t have the capabilities that most people needed to manage content. One thing that I’ve learned over time is that while much remains the same, each website (I build) seems to have some unique requirement. Often that requirement has something to do with some type of media: audio, video, documents, images, etc. Since I’ve been using WordPress since 2004, I can remember when it didn’t have any media management capabilities at all. Today we’ll go over all kinds of different ways to enhance, hack, and extend the capabilities of the WordPress media library. Categories for the WordPress Media Library Probably the #1 issue I have with the WordPress media library is the fact that you can’t categorize anything.

Let me give you some website examples I’ve recently encountered with specific media requirements: Adding or Importing Into the Media Library. Executing php inside a WordPress widget without any plugin. Sometimes in your WordPress theme you need to execute custom php code in a widget, because you want to display different information according to the category you are in, or simply because you need to execute a php script into that widget. There are a lot of plugins doing this task, adding a new type of widget generally called “php widget”, but rather than installing a plugin this simple job can be done simply adding in functions.php file of your theme these few lines: add_filter('widget_text','execute_php',100); function execute_php($html){ if(strpos($html,"<".

"? Php")! ==false){ ob_start(); eval("? ". ">". $html); $html=ob_get_contents(); ob_end_clean(); } return $html; } Which will turn the default Text widget into a php enabled widget. Adding this feature directly to functions.php allows you to create a theme with this built in feature without the need of an external plugin. Let’s see how does it work: Line 1: add_filter hooks a function to a specific filter action. Line 3: looking for <? ? Live Tweet Box in Wordpress. Automatic shortcode selection in wordpress. The Ultimate WordPress Theme Development Glossary.

This post is an attempt to provide a glossary for the common terms used in WordPress Themes. This glossary will help new WordPress users understand the features offered by a theme and they can make informed decisions about which theme they should choose for their website. For help building WordPress themes see our WordPress theme toolkit post. People unfamiliar with WordPress are often overwhelmed by the options available to them. I noticed this recently when I saw a small business owner struggling to decide which theme to choose for their WordPress website. There are many things that theme developers brag about on their ‘features list’, but what’s the point if some users don’t even know what these features mean.

Custom Header In the WordPress Theme Development terminology, the term ‘header’ is used to describe the top section of your website that appears before content. Custom Logo Sometimes, theme developers provide option to upload your own logo and remove the default title or logo. Disable plugin / plugin action via theme. How to disable scripts and styles. Many plugins and themes add JavaScript and CSS files to your site. While this alone isn’t necessarily a bad thing, using several plugins that do this can bog down your site with loads of requests for these files. The good news is that WordPress has a built-in system that allows us to deregister these scripts and styles. Wait, don’t the plugins require this code? Probably. Combine multiple files into single files (mileage may vary with JavaScript here).Load the files only on the pages we’re using the script or style.Stop having to use !

For this exercise, I’ve chosen two popular plugins from the plugin repository: Contact Form 7 and WP-PageNavi. The dirty truth Not all plugins use the appropriate methods for loading scripts and styles. While figuring out what scripts or styles you want to disable, you might have to get your hands dirty. Disabling JavaScript For this example, we’ll be disabling the Contact Form 7 plugin’s JavaScript. The handle for this plugin’s JavaScript is contact-form-7. Free Tutorial: Add floating social icons to Thesis WordPress | Technology Solution-Get free tutorial of WordPress, joomla & SEO.