Hot answers tagged

30

Since WordPress 3.5 this option (XML-RPC) is enabled by default, and the ability to turn it off from WordPress dashboard is gone. Add this code snippet for use in functions.php: // Disable use XML-RPC add_filter( 'xmlrpc_enabled', '__return_false' ); // Disable X-Pingback to header add_filter( 'wp_headers', 'disable_x_pingback' ); function ...


26

The answer by shea is not ideal as in many cases: You don't want to strip everything from <br>, <p> etc. You want it as a default behavior for your WP visual composer which the above code will delete In many cases it is considered as "hacking the core" as this is changing the default core behavior of WP - for example such a thing will not pass ...


24

Here you go ! <?php $my_id = 5369; $post_id_5369 = get_post($my_id); $content = $post_id_5369->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; ?>


17

The wpautop() function adds <p> and <br> tags to your content in order to preserve line breaks. If you would rather add these tags yourself, then you can remove the filters which apply this function to the post content: remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_excerpt', 'wpautop' ); If you would like to keep the automatic ...


11

You are using get_the_content() wrong, it can't take a ID, which is what get_option('page_for_posts') does return, and generally gets the content of the current post inside the loop, in which it has to be used. To get the actual content of that page you can do: $page_for_posts_id = get_option( 'page_for_posts' ); $page_for_posts_obj = get_post( $...


10

Yep, wp_trim_words(): <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>


10

How to trigger an oembed cache regeneration The default cache time is 24 hours and we can adjust it with the oembed_ttl filter. But as you've noticed, expired cache is not enough to trigger a cache regeneration. The reason is this line in the WP_Embed class: if ( $this->usecache || $cached_recently ) { so to trigger a regeneration, we need both ...


9

Wordpress automatically ads the <p> tags to the content. So it shows up while loading the content. This is with the filter wpautop. So we will remove this filter for the image post type only. You can manage this by adding the following code in functions.php file. // Add the filter to manage the p tags add_filter( 'the_content', '...


9

You can use the_content with an high prioriety (lower number). add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, 0); You can even use negative priority: add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, -10); Note that this will apply everytime 'the_content' is used, no matter the ...


9

WordPress has a handy function called post_exists() which allows you to find an existing post by its title, content, and/or date. It returns the post ID on success or 0 otherwise. In your case, you can use $post_id = post_exists( '', '{"member_id":33}' ) to find the post you're looking for. Note: That function doesn't check the post type so you'd need to ...


8

What about if ( !empty( get_the_content() ) ){ //code }


8

When you have the ability to block it via your web server's configuration, @Charles' suggestions are good. If you can only disable it using php, the xmlrpc_enabled filter is not the right way. Like documented here: https://developer.wordpress.org/reference/hooks/xmlrpc_enabled/ it only disables xml rpc methods that require authentication. Instead use the ...


7

We are using the htaccess file to protect it from hackers. # BEGIN protect xmlrpc.php <files xmlrpc.php> order allow,deny deny from all </files> # END protect xmlrpc.php


7

First set the post type to display on main feed page i.e. /feed using pre_get_posts hook $q->set('post_type', array('post', 'page')); On individual page WordPress shows comment feed then set it to false and display page content in feed. $q->is_comment_feed = false; In feed template WordPress calls the_excerpt_rss() which calls get_the_excerpt() so ...


6

$post = get_post( 42 ); $output = apply_filters( 'the_content', $post->post_content ); echo $output; from https://developer.wordpress.org/reference/functions/get_post/


6

Prevent authors from publishing too short content: Here's one idea using a custom post status, for example short: /** * Register a custom 'short' post status * * @see http://wordpress.stackexchange.com/a/159044/26350 */ function wpse_short_post_status() { register_post_status( 'short', array( 'label' => _x( 'Short', '...


6

EDIT After reviewing your edit, you may want to try following These Instructions To embed a video or another object into a post or page, place its URL into the content area. Make sure the URL is on its own line and not hyperlinked (clickable when viewing the post). It sounds like you would want to use wp_get_oembed() - The examples look like this: ...


6

You can use the_post hook to remove <!--nextpage-->. In this case: add_action( 'the_post', 'campaign_remove_nextpage', 99); function campaign_remove_nextpage ( $post ) { if ( ($_GET['utm_campaign']== 'nonextpagecampaign') && (false !== strpos( $post->post_content, '<!--nextpage-->' )) ) { // Reset the global $pages: ...


6

In your dashboard go to settings/permalinks. Hit save. You should be able to see your cpts now.


5

Replace the above mytheme_render_infinite_scroll function with this: function mytheme_render_infinite_scroll() { while ( have_posts() ) : the_post(); if ('mytheme_portfolio' == get_post_type()) : get_template_part( 'content', 'archive-portfolio' ); else : get_template_part( 'content', get_post_format() ); ...


5

You have to define WP_CONTENT_DIR and WP_CONTENT_URL: const WP_CONTENT_DIR = '/path/to/new/directory'; const WP_CONTENT_URL = 'http://content.wp'; The new path must be accessible for read and write operation from the WordPress core directory. You might need a helper function to add the new directory path to the open_basedir list: /** * Add a new ...


5

The internal implementation details of that feature are of questionable sanity. If you take a look at said featured-content.php template you would see that it get posts from twentyfourteen_get_featured_posts() however the only thing that function has is twentyfourteen_get_featured_posts filter from quick look at which in peculiar fashion nothing is actually ...


5

You can disable the visual editor entirely in your profile settings. If you need to disable it on a per page basis, take a look at this answer. Using text mode may not solve the empty paragraph problem, the wpautop filter is applied to the content regardless of how the content is edited. You can remove the filter, but then you'll have to manually break and ...


5

No need to reinvent the wheel - put your editor support back and tweak the settings: function wpse_199918_wp_editor_settings( $settings, $editor_id ) { if ( $editor_id === 'content' && get_current_screen()->post_type === 'custom_post_type' ) { $settings['tinymce'] = false; $settings['quicktags'] = false; $settings['...


5

The best thing to do is disable xmlrpc.php functions with a plugin rather than delete or disable the file itself. The file itself will be replaced on WordPress core updates, while a plugin will keep it disabled after core updates and if you change themes. See https://wordpress.org/plugins/search.php?q=disable+xml-rpc for different plugins. They all have ...


4

you can use this code it is work fine change page_id=19 with your page number: <?php $the_query = new WP_Query( 'page_id=19' ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <?php the_excerpt(); ?> <?php endwhile;?>


4

Per the OP's answer within their question: With your help and some Googling, I put together a shortcode that returns the value of any url parameter. Here it is: //THIS IS A CUSTOM SHORTCODE TO DISPLAY A PARAMETER FROM THE URL function URLParam( $atts ) { extract( shortcode_atts( array( 'param' => 'param', ), $atts ) ); return $...


4

By default, WordPress adds paragraph tags to category descriptions. Stop this by adding the following to your functions.php file // Remove p tags from category description remove_filter('term_description','wpautop'); Simple and easy (codeless). Thank you


4

If you wrap some content in a is_user_logged_in() condition, all that content will only be rendered to users who have an account on your website and are logged into that account. Now, do Google bots have an account on your website? Hell no. So no, that content will never be indexed by Google in your website. Also, it will never be visible to any of your not ...


4

This may not be ideal, but it is a beginning. First make sure that the full content is in the feed: function fullcontentfeed($content) { global $post; $content = $post->post_content; return $content; } add_filter('the_excerpt_rss', 'fullcontentfeed'); You should then see the full feed at this url http://swissaudio.com/craftsmanship/feed/...


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