Cuir stad air ùrachadh bhliadhnaichean ann an gnìomhachas air an làrach WordPress agad leis a ’shortcode seo

Bliadhnaichean ann an Shortcode Gnìomhachais airson WordPress

Is e aon de na rudan as motha mu WordPress an sùbailteachd gus shortcodes a thogail. shortcodes gu bunaiteach tha iad nan sreangan ionaid as urrainn dhut a chuir a-steach don t-susbaint agad a bheir seachad susbaint fiùghantach.

I’m helping a client this week where they’re taking one of their products and rolling it out into a new domain. The site is hundreds of pages and has been quite an undertaking. As we’ve been working on the hit list of issues, one that popped up was that there were dozens of blog posts, pages, and calls-to-action that spoke to the company’s years in business.

Bha 13 air cuid de dhuilleagan, cuid eile 15, bha cuid eile ceart aig 17… uile a rèir cuin a chaidh an sgrìobhadh. Is e seo aon de na deasachaidhean neo-riatanach sin a dh ’fheumas a dhèanamh gus an urrainn do shortcode làimhseachadh gu foirfe.

All we need to do is register a shortcode that takes the current year and subtracts it from the year the company was established. We can register the shortcode and put the function within the site’s theme’s functions.php faidhle:

function YIB_shortcode() {
   $start_year = '2003';
   $current_year = date('Y');
   $displayed_year = $current_year - $start_year;
   $years = $displayed_year;
   return $years;
}
add_shortcode('YIB', 'YIB_shortcode');

Is e na tha an gnìomh a ’toirt air falbh a’ bhliadhna làithreach bho 2003 gus a thighinn suas leis an àireamh iomchaidh de bhliadhnaichean a tha an companaidh air a bhith ann an gnìomhachas.

Mar sin, ma tha mi airson sgrìobhadh dè cho fada ‘s a tha a’ chompanaidh air a bhith ann an gnìomhachas taobh a-staigh susbaint na làraich, tha mi dìreach a ’sgrìobhadh:

Our company has been in business for [YIB]+ years!

Gu dearbh, faodaidh tu a bhith fada nas iom-fhillte leis an t-seòrsa shortcode seo ... dh ’fhaodadh tu HTML, ìomhaighean, CSS, msaa a chleachdadh ach seo dìreach eisimpleir shìmplidh gus dèanamh cinnteach gu bheil an làrach agad ceart mu thràth!

Dè do bheachd?

Tha an làrach seo a 'cleachdadh Akismet gus spama a lùghdachadh. Ionnsaich mar a thathar a 'pròiseasadh an dàta bheachdan agad.