Tag Info

New answers tagged

0

you don't need to add another function to get the search form. If you want to change the look of the search form or add another items you'll have to add the searchform.php to your theme. It could look like this: <form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>"> <input type="search" ...


1

If you're just going to output your own data, there's no reason to wait for the main query to run. Hook parse_request and check if your page was requested and run your code there. function wpd_maybe_output_feed( $request ){ if( isset( $request->query_vars['pagename'] ) && 'gmailrss' == $request->query_vars['pagename'] ){ ...


0

Hey Only Change the code like this function cult_customizer_register( $wp_customize ) { $wp_customize->add_section( 'cult_topic_thumb' , array( 'title' => __( 'Topic of the Week' ), 'priority' => 36, 'description' => 'Allows you to upload an image for your topic of the week section.', ) ); ...


0

The load-scripts.php is concatenation of scripts from performance. It doesn't impact their functionality. As far as I remember there is no way to reuse it at the site's front end. However simply looking up and enqueueing specific scripts you need will work just fine. They will just be loaded in normal fashion, without concatenation step.


0

You would use a conditional check to determine if the option is selected, before adding your function to the action hook. Example: $options = get_option( 'chec_settings' ); if ( $options['chec_checkbox_field_0'] == '1' ) { add_action ('admin_bar_menu', 'remove_wp_logo', 999 ); }


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( ...


0

OK, attempting to remove the with jQuery is counter intuitive. Modifying it via output buffering is inefficient. And we shouldn't edit the actual widget code itself, since this will revert back next time we update WordPress. I would suggest either creating your own text widget, or simply extend and modify the existing WordPress widget as follows (put the ...


0

The reason you get 0 back is because of the test at the end of the function: if ( ! empty( $query->posts ) && $query->is_singular ) return $query->post->ID; else return 0; The posts page doesn't pass the is_singular test so 0 is returned. If you have a URL and want to know if it's the posts page, you can match it against the ...


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


5

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


0

Take a look a this function, it may be useful. WP function get_page_by_path()


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

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

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 ...


0

Hey Change Callback function to like this and add_meta_box to add_meta_boxes hook function create_meta_box_slider() { add_meta_box( 'new-meta-boxes-slider', __('slider Settings'), 'new_meta_box', 'slider', 'normal', 'high' ); } add_action('add_meta_boxes', 'create_meta_box_slider'); function new_meta_box() { global $meta_box_groups; ...


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');


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 ...


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' ); }


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.


-2

here is a video how to set up for posts to be private by default. It is easy. Good luck ! https://www.youtube.com/watch?v=ukAlmqnTbNI


0

The problem was, that I changed the capabilities AFTER I already created the role. I noticed, that if I change the roles slug, the role became duplicated. So I searched, and found remove_role( 'tabellenadmin' ); Add that line somewhere before add_role(). You first have to remove the role, before you can change it.


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"); }


0

See the posts_per_page query var. 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', 2 ); } return $query; }


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

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

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 ...


0

No, unfortunately this is inherent limitation of PHP templates used in WordPress natively. You will have to override either this template file, or file(s) which include it, but in any case something will have to be replaced on whole file scope. There is no clean way to load template file partially in WordPress, which is handled by template inheritance ...


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 ...


0

Thank you @bueltge for the answer! I was focusing on the shortcode and didn't even think to call the function in the 'normal' way. echo dynamicContent() worked.


0

To be really honest here, there is no method in determining a paragraph. Yes, Wordpress has a filter called wpautop that set p tags (paragraphs) based on double line breaks, and that is all that Wordpress defines as a paragraph, a piece of text separated by a double line break from another piece of text. Lets look at the screenshot from the HTML from a ...


0

I have modified the earlier solution to your needs. You need to change following line $wpse0001_excerpt = substr( $wpse0001_excerpt, 0, strpos( $wpse0001_excerpt, '</p>' ) + 4 ); to this $wpse0001_excerpt = explode('</p>', $wpse0001_excerpt, 3); // unset the rest of the contents if(isset($wpse0001_excerpt[3])) ...


0

The answer is that you can't do it without using comments.php. Since WordPress 2.7, comments.php is important to display full features and customizable comments rest if you still want to use <?php comments_template(); ?> then you can edit anything in it except CSS.


0

On top of my head scheme like this should work: // functions.php function prefix_get_settings() { return array('haha' => 'hehe'); } add_filter( 'prefix_default_settings', 'prefix_get_settings', 9 ); // plugin $default_settings = apply_filters( 'prefix_default_settings', array() );


0

Place this code snippet put in function.php, this should give you what you need. function my_theme_wp_title( $title, $sep ) { global $post; /* my other title cases */ //get post's modified date $m_date = get_the_modified_date(); //concatenate the current title with the date string, using the separator to be more clear $title .= ...


-1

Kindly refer below : <?php if (get_the_modified_time() != get_the_time()) : ?> <p>Posted: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, Last Updated: <?php the_modified_time('F j, Y'); ?> at <?php the_modified_time('g:i a'); ?></p> <?php else: ?> <p>Posted: <?php ...


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( ...


0

You can also rewrite URL using htaccess, it can also redirect to a pretty URL. Just put this code into your .htaccess file. RewriteEngine On RewriteRule ^my-question/([^/]*)$ /my-question/?template=$1 [L] Or You can also done it with functions.php using following code snippet. global $wp_rewrite; add_rewrite_rule('^my-question/([^/]*)?$', ...


0

Update: I've come to realize that we have different goals... @NewUser accepts that both URL styles work: http://example.com/post-title/?template=basic and http://example.com/post-title/template/basic. While my goal is to never see http://example.com/post-title/?template=basic, by having it redirect to a pretty URL. Just like domain.com/?p=100 redirects ...


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', ...


0

You should take a look at the WordPress hierarchy page in the documentation. Here it's the relevant part: page-{slug}.php - If the page slug is recent-news, WordPress will look to use page-recent-news.php http://codex.wordpress.org/Template_Hierarchy



Top 50 recent answers are included