1

Ideally, the goal is to show the block number (ie: 782667) instead of the date value (ie: 26 March 2023 4:44PM CT) on all wordpress posts and pages that currently display it.

There's maybe a script we can add to the functions.php in the wordpress child-theme currently in user?

3
  • 3
    What is a block number? Commented Mar 27, 2023 at 14:56
  • do you mean post ID? There's no such thing as "block number", if it's not the posts ID you're going to have to be more specific about what it is and where it comes from
    – Tom J Nowell
    Commented Mar 27, 2023 at 16:27
  • Thanks for your responses. The blockNumber is the sequential number of a block mined in the bitcoin blockchain, every block is mined in a specific time, one every 10-15 min circa. For example, block number 783184 was mined on 2023-03-30 07:02. Ideally the function will read the post/page date and convert it at blockNumber. Not sure is clear but please let me know if you have any further questions
    – SuperAtic
    Commented Mar 30, 2023 at 13:22

2 Answers 2

3

I have no idea what a 'block number' is, but when themes output the date for a post they will use either the_date() or the_time() (or both). You can replace the output using the filters the_date() or the_time():

add_filter(
    'the_date',
    function( $the_date, $format ) {
        $block_number = 'whatever a block number is';
        
        return $block_number;
    },
    10,
    2
);
4
  • Please see response on comment id="comment-606263" above 👆
    – SuperAtic
    Commented Mar 30, 2023 at 13:29
  • Ok well in that case getting the actual block number doesn’t have anything to do with WordPress. You’d just need to add whatever code is required to get that number and use it in the code from this answer. Commented Mar 30, 2023 at 14:35
  • Ok, thanks for your contribution, we're trying now to understand what API source to use and how to write the request into the function.php
    – SuperAtic
    Commented Mar 30, 2023 at 15:39
  • 1
    Those questions are asking in the context of WordPress, which is not relevant. You want to know how to get the number in PHP. Ask that and you’re more likely to get good answers. Once you have that you can plug it into the code I’ve given here. Commented Mar 30, 2023 at 17:16
0

We ended up building Bitcoin Block Date Converter, a plugin for WordPress and compatible with the majority of themes using this for

$ date -ud "1/1/2017"
Sun Jan 1 00:00:00 UTC 2017
$ date -ud "1/1/2017" +%s
1483228800

+add three zeroes to that number and append it to a blockchain.com URL:

https://www.blockchain.com/btc/blocks/1483228800000

And there you have it the block number:

446033 (Main Chain) 2017-01-01 00:02:33

For more info:

Repo on GitHub

Demo web site

Donate on Geyser

.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.