• Is there a way to?

    F.i., say I would like to write into a post something like «we have xxx posts as of today», where xxx should be a value of a variable?

    Thank you.

Viewing 1 replies (of 1 total)
  • The ways I can think of to do this would be a plugin that allows php code to be written into the posts.

    There are some, but none I can see that look to have been updated for over a year.

    The other is to create a function of your own in functions.php which will allow you to add a shortcode to the posts.

    Then use wp_count_posts()

    Untested Function WARNING:
    This code should not be tested on a production website only test on a local install.

    function my_post_count() {
    	$count_posts = wp_count_posts();
    	$published_posts = $count_posts->publish;
    
    	return 'we have ' .$published_posts. 'posts as of today';
    }
    add_shortcode('post_count', 'my_post_count');
    add_filter('my_post_count', 'do_shortcode');
    /* End Shortcode Post Count [post_count] */

    In the post you would use a shortcode

    Did you know that [post_count], why not check out some of the others?

    HTH

    David

Viewing 1 replies (of 1 total)

The topic ‘inserting a variable's value into a post’ is closed to new replies.