Hide parts of the post content on the home page

If your video is pasted into the post body, you have a couple of options. Use a filter on the_content and preg_replace to remove the content. Wrap your content in a shortcode. I am going to recommend option #2 because option #1 involves processing markup with regex which is tricky and prone to error, and … Read more

Mass Update lines of code for all posts

This script will get all posts and replace it content according to your needs: function wpse_287574_replace_content() { // Get all posts $query = new WP_Query(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, )); $posts = $query->get_posts(); foreach ($posts as $post) { // Get content $content = $post->post_content; // Regex and replacement $regex = ‘/^(\<a\s+data-name=\”.+\”)(\>(.+)\<\/a\>)$/’; $replacement=”$1 href=”https://wordpress.stackexchange.com/items/?item=”$2″; … Read more

How to extract images of post and pages excluding header and logo image in wordpress?

I believe this will get you all of your attachments: $q = new WP_Query( array( ‘post_type’=>’attachment’, ‘post_status’=>’inherit’ ) ); var_dump($q); You could further restrict that by adding other parameters, for example, ‘post_mime_type’ => ‘image’ would restrict only to images. That will return all images though, not just the ones attached to posts. What you want … Read more

Odd/even class on article tag

Try this (untested): <?php $zebra = (++$j % 2 == 0) ? ‘evenpost’ : ‘oddpost’; ?> <article id=”post-<?php the_ID(); ?>” <?php post_class(‘clearfix span4 ‘ . $zebra); ?> role=”article”> You just need to place theodd/even class into a variable before passing it to post_class.

Text after more tag in posts

This will add your code after the more tag area on the post page: add_filter(‘the_content’, ‘adds_block’); function adds_block($content) { if (is_single()) { // return $content; global $post; $thePostID = $post->ID; $test=”<span id=”more-” .$thePostID.'”></span>’; return str_replace($test, ads(), $content); } } function ads(){ return ‘Your Custom Code,,’; }

Filter post before *editing*

You can use the the_editor_content filter: function wpa_editor_content( $content ) { global $post; return “this post’s id is $post->ID ” . $content; } add_filter( ‘the_editor_content’, ‘wpa_editor_content’ );

WP get_permalink Return Wrong URL

IMO It is rarely a good idea to evaluate shortcodes outside of the specific post page as too many times you need the context for either the evaluation itself or styling. Your problem is most likely related to the use of the_post and wp_reset_postdata. What is exactly the post being reset to in that case? … Read more

Get post embedded image caption

If I understood correctly, you are trying to add, to every image embedded in a post gallery, a custom rel attribute and a title attribute based on the attachment caption. Instead of parsing the content, you can try to modify the anchor that wraps the images using the ‘wp_get_attachment_link’ filter. <?php function wpse221533_add_caption_title_to_content_gallery_image_attachments( $markup, $id, … Read more

Comments enabled, but disabled at the same time

You can try the following function: function enable_comments() { update_option( ‘default_comment_status’, ‘open’ ); } add_action( ‘after_setup_theme’, ‘enable_comments’ ); This should enable comments for all new posts. On the other hand have you checked your theme? Some themes for some reasons have build in functions that overrides the default WP comments behavior.