Tag Info

Hot answers tagged

4

In the tutorial (Example 1), he has to declare the global $post so that he can access the post_parent from it. In a function like that, the $post is not a global variable unless he makes it so. In the codex (Example 2), it is declared global because the sample code is just a sample, explicitly trying to tell you that the $post variable is a global one. ...


3

You can use this function wp_strip_all_tags. strlen( wp_strip_all_tags($post->post_content)); With that you get rid of all the HTML tags. Just a little extra detail, you might want to strip the shortcodes, too. You can use this function strip_shortcodes You will end up with something like this: strlen( ...


1

You are right in assuming that $post->post_content contains tags and other not textual entities like shortcodes. You can use strip_tags to get rid of the tags but you will probably want to expand the shortcodes first. resulting in something like $count = strlen(strip_tags(do_shortcode($post->post_content)); And it will still give you the wrong ...


1

As this line of code is hardcoded in the index.php file rather than called via a function you only really have two options: Write your own function to call this code (with your chosen read more text), then replace the relevant section in the child theme's index.php file with a call to this function. The function would go in your child theme's functions.php ...


1

Take a look at PHP's array_values function. Alternatively, you could typecast. Note that if the array is in serialized form as you have put it above, you will have to unserialize it first, in either case. $numerical_array = array_values( unserialize( 'a:1:{s:8:"post-134";s:3:"134";s:8:"post-136";s:3:"136";}' ) ); or $numerical_array = ...


1

It means Wordpress is outputting something to the browser too early. The file indicated seems to be your own session file (php stores user sessions in small text files in the tmp directory). Check first the wp-config.php file. Remove the final closing php tag. Make sure you're not outputting anything in that file (look for print_r, var_dump, echo, print, ...


1

All actions are actually filters internally. So yes, you can do things in a filter hook. However, be mindful of which filters and what you're doing. Some filters are ran everywhere, and doing expensive operations on them may lead to massive slowdowns. Also beware of recursion. If your expensive operation triggers the very filter you've hooked on to..


1

The $post global variable is set by $wp_query->the_post() (WP_Post) inside the loop and is accessible during the loop. $post holds the post data from the current post. When you are inside the loop, you don't need to call the $post global, as it is already accessible. When you are outside the loop, and you need to access post data, you need to make use ...


1

Install plugin: https://wordpress.org/plugins/force-regenerate-thumbnails/ and regenerate all thumbnails. Or steps: Create new dimension for images: add_image_size ('thumb-cropped', 227, 133, true); // Set necessary sizes (true = cropped) Get images with the sizes in you function. get_the_post_thumbnail($post->ID); fix to: ...


1

Just because you think that you have to do it doesn't remove the fact that it is very not smart to do it. The plugin code is built to be used as a plugin and not as a theme, and while you can copy parts of the code and use them in the theme there can not be any simple way to make sure there is no dependency left somewhere in the code. The easiest way to do ...



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