Tag Info

Hot answers tagged

4

As @cybmeta already pointed out, you are too early with your removal. So you have to defer the actual removal, for instance like so: add_action( 'after_setup_theme', 'wpdev_170663_remove_parent_theme_stuff', 0 ); function wpdev_170663_remove_parent_theme_stuff() { remove_action( 'after_setup_theme', 'et_pb_setup_theme' ); }


4

Try this: if ( has_excerpt( $some_post_id ) ) { // Do something here? } else { // Or here? } References: has_excerpt


2

This is an alternative to the answer by @tf The manual excerpt set by a user is stored as a WP_Post object, $post_excerpt. post_excerpt string User-defined post excerpt You can access this excerpt inside the loop with $post->post_excerpt You can simply do a check to see if this object is empty or not


2

You should use do_shortcode() function in both strings you are returning it will execute the shortcodes in the string. function oldStuff(){ return do_shortcode(' [new] only raw html is in this function '); } add_shortcode('old', 'oldStuff');


2

Plugins load before themes. The earliest hooks available to plugins is plugins_loaded (or muplugins_loaded for mu-plugins), while themes run on after_setup_theme and later hooks. So you better just load the file [that contains the class] on a specific hook in your plugin. It probably is best to load it on a lower priority than the default 10. Below I use 5 ...


2

include the conditional tag is_paged() within your if statement; example: if ( $i == 1 && !is_paged() ) :


2

You can make use of the build in loop counter, $current_post which you can access in the main query with $wp_query->current_post. (Just a note, the counter starts at 0, so post 1 will be 0) The main query uses WP_Query, $wp_query being the query variable used, so have a look at the Methods and Properties which you can make use of and the uses of these ...


1

Here is my take on things. I have scrapped your complete idea and went with an alternative solution which doesn't use SQL. I have done some testing and found my method to be much faster that the code in your question THE IDEA: You first need to get the current post id, which I get through get_queried_object_id(). The post ID will be used to retrieve: The ...


1

You have a couple of flaws in your code get_post_meta( 'fap_referral_link' ) should be get_post_meta( $post->ID, 'fap_referral_link', true ). Please see get_post_meta() You should always first check if you actually have posts before you run your foreach loop Never ever use extract(). It uses eval() which stand for EVIL. This has been completely removed ...


1

This should do the trick: add_action( 'pre_get_posts', 'add_tours_post_type_to_query' ); function add_tours_post_type_to_query( $query ) { if ( is_home() && $query->is_main_query() ){ $query->set( 'post_type', array( 'tours' ) ); $query->set( 'posts_per_page', 1 ); } return $query; } For the future the Codex can be your ...


1

Each time you're making an ajax call, $_TEST = 0; is being evaluated again. You use the options API to manipulate your variable. function get_global_val() { $count = get_option( 'mycount' ); $count++; //or whatever you want to do with it update_option( 'mycount', $count ); die("New value is $count"); }


1

The functions.php file of child themes is loaded right before the parent theme functions.php, so when you run remove_action in child theme, the action you are trying to remove doesn't exist beacuse it is added later.


1

I think that your problem is ajaxurl is not available for your script. Try to defined that varibale before your js code is loaded. The best way is using wp_localize_script: The PHP: add_action( 'wp_enqueue_scripts', 'cyb_enqueue_scripts' ); function cyb_enqueue_scripts() { //Change the key and url with yours wp_register_script('my-js', ...


1

Your should add rewrite endpoint template on theme activation hook and init hook. Also there is some little checks to perform to prevent errors. function sjc_theme_activate(){ sjc_theme_add_rewrite_endpoint(); flush_rewrite_rules(); } //for more info http://codex.wordpress.org/Plugin_API/Action_Reference/after_switch_theme add_action( ...


1

Technically your first example is also incorrect, but the problem is not apparent. You're using template tags that themselves echo their content. For example, you can write simply: the_permalink(); without echo, and the permalink will be output. This is because that function echoes its value. To output the permalink within an echo or variable assignment ...


1

This should just be an extension to the answer by @Milo There are a couple of flaws in your code You should not be using extract(). It is hard to debug and causes unexpected output. All instances of extract() was removed from core PHP 5.2 is dead, and for that matter 5.3 aswell. create_function() is pre 5.3. This is one big security risk as it uses eval() ...


1

is_page() relies on a complete global $wp_query object. If you call it before the action template_redirect has been fired, it might be impossible to get that data. Wait for a proper action. Example: add_filter( 'template_include', function( $template ) { if ( is_page( 27 ) ) echo 'this is the apply page'; return $template; }); You can ...


1

Use the following code in the functions.php file at your theme's folder function my_enqueue($hook) { if ( 'edit.php' == $hook ) { return; } wp_register_script( 'xxx', get_template_directory_uri() . '/includes/js/slider.js', array( 'jquery' ) ); wp_enqueue_script( 'xxx' ); } add_action( ...


1

I'm afraid I cannot replicate your problem. I'm uncertain as to why it is going wrong as I cannot see the loop that is being used, but a way that you could probably ensure it works is to adjust your function to accept a $post input: //Social Media function showSocialButtons( $post = null ) { if( ! $post ){ global $post; } //The output ...


1

I found the solution from a Wordpress forum and this is what they used. Works perfect <?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), '' ); $image = $image[0]; ?> <?php else : $image = get_bloginfo('stylesheet_directory') . ...



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