Tag Info

Hot answers tagged

12

Your question is a bit specific if you "only" want to automatically import some posts/pages. There are other ways to do this then using a XML export file. If you have text-only posts, then you should use LOAD DATA INFILE. At first you have to export your posts. global $wpdb, $wp_filesystem; $tables = array( 'posts' => array( 'posts', ...


11

The default response from admin-ajax.php is, die( '0' ); ...by adding your own exit() or die() after returning your desired content prevents the default response from admin-ajax.php being returned as well. It also generally means that your ajax call has succeeded. Ultimately, to answer your question, it's meant to work this way. What you are doing by ...


9

Our journey starts here with the WP_Customize_Background_Image_Control class, which is a WP_Customize_Image_Control. I'd imagine offering these built-in backgrounds in a new tab alongside the existing Upload New and Uploaded tabs. There are at least two ways of achieving the following: either creating your own modified class based off of the ...


9

Add this snippet to your functions.php function redirect_the_single_post() { if (is_search() && is_main_query()) { global $wp_query; if ($wp_query->post_count == 1 && $wp_query->max_num_pages == 1) { wp_redirect( get_permalink( $wp_query->posts['0']->ID ) ); exit; } } } ...


7

Use a plugin for that. Hook into after_setup_theme and check if the current theme is the correct child theme: add_action( 'after_setup_theme', 'common_child_theme_functions' ); function common_child_theme_functions() { if ( 'Twenty Twelve' !== wp_get_theme()->parent() ) return; // do your work } wp_get_theme() returns a WP_Theme ...


7

There are a couple of problems with your code: You have to close the PHP context, if you want to output plain HTML: function foo(){ ?><strong><?php } Don’t repeat yourself. Always store repeating values in variables or functions. Writing <a href more than once is a bug. Do not use get_the_title() in attributes. Use the_title_attribute( array ...


7

This has always been a bugbear for me - the lack of on-demand image sizing, and the subsequent number of files you can end up with if you have lots of sizes! I can see the logic behind your efforts - the trouble is, add_image_size only truly comes into play at point-of-upload. As such, is_page_template(..) will always be false. A quick google dug up Aqua ...


6

Well, I'd say that you need a custom plugin. All the rationale is in this Q&A: Where to put my code: plugin or functions.php? Also related: Where do I put the code snippets I found here or somewhere else on the web? Create a Functionality Plugin Instead of Using Functions.php And answering to the Question, create the following file ...


6

The if function_exists approach allows for a child theme to override the function definition by simply defining the function themselves. Since child theme's functions.php files load first, then they will define the function first and the parent's definition will not get loaded. The other approach of using action or filter hooks works just as well, and child ...


6

The Reply links I assume your Reply links look like this: <a class="comment-reply-link" href="/2013/12/29/hello-world/?replytocom=32#respond" onclick="return addComment.moveForm('comment-32', '32', 'respond', '1')">Reply</a> and the Cancel Reply link: <a rel="nofollow" id="cancel-comment-reply-link" ...


5

This answer contains a fairly simple CSS solution. Essentially, you'd add the following to your stylesheet: .cat-item cat-item-7 { list-style-image: url('my-epic-news-icon'); } cat-item cat-item-11 { list-style-image: url('my-epic-jquery-icon'); } etc Yes, it's not a very dynamic solution, but your categories aren't likely to change I ...


5

There is no real difference between the two methods. When using method A, only the hooking is bound to the condition (i.e., the function is defined no matter what), while in method B the definition of the function as well as the hooking is. Another thing is the following method (which you did not include): function my_hooked_function() { if (! ...


5

The second $item argument, which is being made available to your filter function, contains a menu item object. If dumped it looks something like this: [1] => WP_Post Object ( [ID] => 2220 [post_author] => 1 [post_date] => 2012-12-26 19:29:44 [post_date_gmt] => 2012-12-26 17:29:44 [post_content] ...


5

To exclude a category, you need to know its ID. You can then exclude it like this (please not the minus before the ID): $args = array( 'posts_per_page' => 4, 'cat' => -the_category_id_to_put_in); The WP Query class reference has more information if you need it: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters


4

And there is another filter that will give you access to the $header variable which can allow you to BCC your emails so that you get a carbon copy of every email that goes to your clients on Woocommerce. This is just as easy as the code above except your clients will not see your email address. Just like the solution above you would add the following code: ...


4

Allow me to re-introduce 2 things here: (a) "I am not asking how to... I've got that part sorted..." »» I've learnt over time to be OK with the fact that the approach to issues/fixes doesn't necessarily require some 'visible association' with the issue at hand. (b) "...would I have to do to strip out the parts..." "...clients are tradesmen, so even ...


4

Because of backwards compatibility. You can use the same callback for multiple filters. Inside of that callback you should use current_filter() to determine the context. But some plugins use the number of passed arguments instead. Changing that would break these plugins. That’s why you should always use the API (here: current_filter()) and not some ...


4

Why don't you use WordPress get_posts? You can add the parameter orderby => 'title' as you want. $args = array( 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'title' ); $posts = get_posts( $args ); print_r($posts); If you want the sql you can just add ORDER BY post_title: SELECT * FROM $wpdb->posts ...


4

t f's answer got me thinking. Actually, I can use the core function and adapt it as I like but just put everything in a new function. So here goes: function my_wp_is_mobile() { static $is_mobile; if ( isset($is_mobile) ) return $is_mobile; if ( empty($_SERVER['HTTP_USER_AGENT']) ) { $is_mobile = false; } elseif ( ...


4

Specifically editing the code you provided in the original question: add_filter( 'nav_menu_link_attributes', 'wpse121123_contact_menu_atts', 10, 3 ); function wpse121123_contact_menu_atts( $atts, $item, $args ) { // The ID of the target menu item $menu_target = 123; // inspect $item if ($item->ID == $menu_target) { $atts['data-toggle'] = ...


4

Checking to see if built in WordPress functions exist before calling them is for backward compatibility which IMHO is not needed. So if you see if ( function_exists( 'register_nav_menus' ) ) the theme author is supporting versions earlier than 3.0. You still sometimes see if ( function_exists( 'dynamic_sidebar' ) ) Why? I couldn't tell you because ...


4

Basically every filter has to be registered in the original function code (since a filter is just a way you can overwrite what is happening in the default function). So before you can attach your custom function to a filter using add_filter() the filter has to be registered before with apply_filters() (there are other functions which do the same - but this ...


4

The problem with the code in your question is it always intercepts. You completely lose the ability to not publish, no drafts possible. Why this leads to untrashable post is something I didn't inspect further. Anyway this isn't what one wants. I'm glad the javascript solution is working for you, but personally I have two problems with it, first, you can ...


4

The two functions output exactly the same thing. From the Codex entry for get_bloginfo(): 'name' - Returns the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. From source: case 'name': default: $output = get_option('blogname'); Neither get_bloginfo() nor bloginfo() do any sort ...


4

Your problem is here: $welcomePage = get_post( 5 ); echo $welcomePage -> post_content; Shortcodes are processed on display by via a filter on the_content which is called by the function the_content(). You've bypassed that functionality and are echoing the raw post data. You need to output your code using a proper Loop or explicitly process the ...


4

Assumptions: You don't explain how you want to install the Font Awesome package, so I just assume for the moment that you use the plugin Font Awesome Icons. You wrote: Before anyone says use a background image, I do not want to do that. I would like it to be physical. so I assume you want to use the <i> tag directly, for example: <i ...


4

If it is a custom theme for your site then there would no great speed or security improvements by moving functions. On the other hand if you want to distribute the theme then I recommend having only the minimum php in the page templates files and having the rest of the functions organized in different files. I like the basic theme set up files of the theme ...


4

Assuming that you want to use the fa-chevron-right icon, you simply need to target the list item via CSS. Use the :after pseudo-class: .list-item:after { font-family: FontAwesome; // or whatever the font awesome family is registered as content: '\f054'; } Edit So, to give an idea of how you might pass dynamic CSS (which can be easily adapted to a ...


4

Disclaimer: - This isn't actually an answer. - It is intended to help you with your additional research on the topic. - Furthermore it is reflecting a - at least felt - lately more frequent occurrence of similar questions regarding similar problems. Additional information regarding this topic on Wordpress Development: Removing Image Sizes for ...


4

What you are looking for is a "MU-Plugin"-- "Must-Use Plugin".. Originally these were called "Multi-User Plugins" and were intended for exactly your purpose-- to provide a way for site admins to enable functionality on all sites of an installation. Create a directory at /wp-content/mu-plugins/ and put your PHP file(s) in it. WordPress will load the files ...



Only top voted, non community-wiki answers of a minimum length are eligible